Jed Parsons wrote:
>
> Rollin' on to another question :)
>
> How do I refine this so that it works for an element called 'para', but
> leaves ENTER inserting a '\n' in paras that have xml:space 'preserve'?
>
> To state the desired behavior:
>
> ENTER bound to "addSameAfter" for certain nodes that do NOT have
> xml:space set to 'preserve'
> ENTER inserts a simple '\n' in all other cases
>
> I can't figure out how to select an element by attribute in a command.
>
I've tested the bindings and the macros below with XHTML:
---
<command name="addSameAfter">
<macro>
<sequence>
<command name="selectNode"
parameter="ancestorOrSelf[implicitElement] p pre li" />
<command name="insertNode" parameter="sameElementAfter" />
</sequence>
</macro>
</command>
<!-- modifiers="mod" means Command on the Mac and
Control on all other platforms. -->
<binding>
<keyPressed code="F2" modifiers="mod" />
<command name="addSameAfter" />
</binding>
<command name="insertNewlineOrAddSameAfter">
<macro>
<choice>
<command name="insertControlChar" parameter="\n" />
<command name="addSameAfter" />
</choice>
</macro>
</command>
<binding>
<keyPressed code="F2" />
<command name="insertNewlineOrAddSameAfter" />
</binding>
---
I used code="F2" instead on code="ENTER", because the stock
configuration for XHTML already defines bindings using code="ENTER".
In your case, simply replace code="F2" by code="ENTER" and "p pre li" by
your own block level elements.
The basic idea is to bind Ctrl-Enter to macro addSameAfter to allow for
duplicating elements, even for those having xml:space="preserve"[*].
But simply pressing on the Enter key is smarter. It first attempts to
insert a newline character (command insertControlChar -- see
http://www.xmlmind.com/xmleditor/_distrib/doc/commands/insertControlChar.html)
and if (the <choice> construct) this operation is rejected by the
element, it duplicates the element.
---
[*] And, also having in the CSS style sheet, property "white-space:
pre;" (*both* *conditions* *are* *mandatory*).