Creating shortcut for note tag with para

Ioana
Posts: 13
Location: Bucharest, Romania

Creating shortcut for note tag with para

Thu Oct 31, 2013 2:40 pm

I'm trying to add a new DocBook action in Options > Preferences > Document Type Associations and I managed to do it halfway, but I got stuck. What I would like is to create a "note" shortcut, which would enclose the selected text like so:

Code: Select all

<note><para>My text</para></note>
. I figured out how to enclose the text in

Code: Select all

<note> </note>
tags, but I don't know how to get oXygen to add that second level of

Code: Select all

<para> </para>
. Is this possible? Thanks in advance!
Radu
Posts: 5088

Re: Creating shortcut for note tag with para

Thu Oct 31, 2013 3:06 pm

Hi Ioana,

So in the Preferences->Document Type Association options page you edited the Docbook (4 or 5) document type, right?
Then in the Author->Actions tab you probably created a new action and then customized it in the dialog:

http://www.oxygenxml.com/doc/ug-oxygen/tasks/dg-insert-section-action.html

For this action you should choose an operation of type ro.sync.ecss.extensions.commons.operations.SurroundWithFragmentOperation and as the fragment of the operation you should set:

Code: Select all

<note><para/></note>


The surrounded text will be set in the first leaf of the inserted XML fragment.

Another alternative to defining an action (if you just want this for personal use) is to create a new code template in the Editor / Templates / Code Templates Preferences page. A code template can use editor variables like ${selection} and it appears in the content completion window when pressing ENTER in the Author mode.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Ioana
Posts: 13
Location: Bucharest, Romania

Re: Creating shortcut for note tag with para

Thu Oct 31, 2013 4:35 pm

Thanks Radu! I was using SurroundWithElementOperation, not SurroundWithFragmentOperation. I used the correct operation and now it's working.

Two additional questions:
1. When I use the new action, the following is inserted:

Code: Select all

<note xmlns="">

Can I set this up so that xmlsn is not inserted, so that I get a simple <note>?

2. My text is already between <para> tags. Is it possible to delete these when I use the new action?
For example, I have:

Code: Select all

<para>This should be a note.</para>

When I use my new actions, I get:

Code: Select all

<para><note><para>This should be a note.</para></note></para>

Is there a way to get rid of that initial <para> tag, so that the result would be

Code: Select all

<note><para>This should be a note.</para></note>
Radu
Posts: 5088

Re: Creating shortcut for note tag with para

Thu Oct 31, 2013 5:10 pm

Hi Ioana,

Please see some comments below:

1. When I use the new action, the following is inserted:

Code: Select all

    <note xmlns="">


Can I set this up so that xmlsn is not inserted, so that I get a simple <note>?


So you are using Docbook 5. The XML fragment which you specify in the action mode should be like:

Code: Select all

<note xmlns="http://docbook.org/ns/docbook"><para/></note>


The namespace attribute will be stripped by Oxygen when the fragment is inserted because it is already declared in the XML document. So the XML fragment needs to be self contained, to specify all namespace declarations on it.

2. My text is already between <para> tags. Is it possible to delete these when I use the new action?


An action can have several action modes.
Each action mode defines an XPath expression in the context of which the mode will be called.
So in your case the action could have two action modes:

1) The first action mode would have the activation XPath ancestor-or-self::*:para and would call the SurroundWithFragmentOperation with the XML:

Code: Select all

<note xmlns="http://docbook.org/ns/docbook"/>


This mode would get triggered when the caret is already inside a paragraph.

2) The second mode would be a fallback, it could have the XPath true() and would call the SurroundWithFragmentOperation with the XML:

Code: Select all

<note xmlns="http://docbook.org/ns/docbook"><para/></note>


Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Ioana
Posts: 13
Location: Bucharest, Romania

Re: Creating shortcut for note tag with para

Thu Oct 31, 2013 6:59 pm

1. Yes, DocBook5. I added the namespace declaration and now it's working fine.

2. I think I'm doing something wrong here. I defined the two action modes and tried to apply them in two ways, but I'm not getting the right results.
a. If I select the paragraph (with the mouse) and use my shortcut. I get the note inside of the paragraph:

Code: Select all

<para><note>Note text</note></para>

b. If I select the paragraph by clicking on "para" in the breadcrumbs and use my shortcut, I get two paragraphs:

Code: Select all

<note><para><para>Note text</para></para></note>


On the bright side, I realized that if I define the action without an activation XPath, with a <simple note> tag, and I select the paragraph by clicking the breadcrumb, it does exactly what I want :)
Radu
Posts: 5088

Re: Creating shortcut for note tag with para

Fri Nov 01, 2013 11:31 am

Hi Ioana,

Please see some comments below:

a. If I select the paragraph (with the mouse) and use my shortcut. I get the note inside of the paragraph


This is because you are only selecting the text inside the paragraph and not the entire paragraph.
On the toolbar there is a drop-down button allowing you to configure if tags are visible or not in the editor. You can switch to "Full Tags" to see what exactly is selected in the editor:

http://www.oxygenxml.com/doc/ug-oxygen/index.html#topics/author-display-markup.html

You can also click an element's tag to select it completely, the same thing as clicking the element in the Breadcrumb or in the Outline view. Or you can triple click inside the paragraph to select it completely.

b. If I select the paragraph by clicking on "para" in the breadcrumbs and use my shortcut, I get two paragraphs:


Indeed clicking in the breadcrumb allows you to select completely an element.
The problem when an element is fully selected is that the caret is actually after the element (after the element's end tag) and the XPath activation expression looks at the caret position.
We added a special XPath function in Oxygen 15.1 to address such cases:

http://www.oxygenxml.com/doc/ug-oxygen/#topics/oxy-current-selected-element.html

So for the case in which an entire paragraph is selected and if you are using Oxygen 15.1, the XPath activation expression would be:

Code: Select all

oxy:current-selected-element()[self::*:para]


and it would call a surround operation with the XML fragment:

Code: Select all

<note xmlns="http://docbook.org/ns/docbook"/>


Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Ioana
Posts: 13
Location: Bucharest, Romania

Re: Creating shortcut for note tag with para

Fri Nov 01, 2013 4:25 pm

Thanks for the detailed explanations! I'll update to 15.1 and update my action.

Return to “DocBook”

Who is online

Users browsing this forum: No registered users and 0 guests