Creating shortcut for note tag with para
-
- Posts: 13
- Joined: Mon Oct 07, 2013 6:04 pm
- Location: Bucharest, Romania
Creating shortcut for note tag with para
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: . I figured out how to enclose the text in tags, but I don't know how to get oXygen to add that second level of . Is this possible? Thanks in advance!
Code: Select all
<note><para>My text</para></note>
Code: Select all
<note> </note>
Code: Select all
<para> </para>
-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Creating shortcut for note tag with para
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/ ... ction.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:
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
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/ ... ction.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>
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
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 13
- Joined: Mon Oct 07, 2013 6:04 pm
- Location: Bucharest, Romania
Re: Creating shortcut for note tag with para
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:
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:
When I use my new actions, I get:
Is there a way to get rid of that initial <para> tag, so that the result would be
Two additional questions:
1. When I use the new action, the following is inserted:
Code: Select all
<note xmlns="">
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>
Code: Select all
<para><note><para>This should be a note.</para></note></para>
Code: Select all
<note><para>This should be a note.</para></note>
-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Creating shortcut for note tag with para
Hi Ioana,
Please see some comments below:
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.
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:
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:
Regards,
Radu
Please see some comments below:
So you are using Docbook 5. The XML fragment which you specify in the action mode should be like:1. When I use the new action, the following is inserted:
Can I set this up so that xmlsn is not inserted, so that I get a simple <note>?Code: Select all
<note xmlns="">
Code: Select all
<note xmlns="http://docbook.org/ns/docbook"><para/></note>
An action can have several action modes.2. My text is already between <para> tags. Is it possible to delete these when I use the new action?
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"/>
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>
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 13
- Joined: Mon Oct 07, 2013 6:04 pm
- Location: Bucharest, Romania
Re: Creating shortcut for note tag with para
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:
b. If I select the paragraph by clicking on "para" in the breadcrumbs and use my shortcut, I get two paragraphs:
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 
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>
Code: Select all
<note><para><para>Note text</para></para></note>

-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Creating shortcut for note tag with para
Hi Ioana,
Please see some comments below:
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/ ... arkup.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.
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/ ... ement.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:
and it would call a surround operation with the XML fragment:
Regards,
Radu
Please see some comments below:
This is because you are only selecting the text inside the paragraph and not the entire paragraph.a. If I select the paragraph (with the mouse) and use my shortcut. I get the note inside of the 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/ ... arkup.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.
Indeed clicking in the breadcrumb allows you to select completely an element.b. If I select the paragraph by clicking on "para" in the breadcrumbs and use my shortcut, I get two paragraphs:
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/ ... ement.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]
Code: Select all
<note xmlns="http://docbook.org/ns/docbook"/>
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service