 Nux
Member
|
Hi.
I often use PN to edit xml-like files. An option to auto-close tags is nice, but not sufficient if you already have a text which must be enclosed in tags. I could use text-clips for that, but I would like to be able do that with keyboard like this:
- Select text.
- Press some key (e.g. CTRL+SHIFT+T) → dialog with an input appears.
- Write tag name (and optional attrs after space).
- Press ENTER → tag is inserted around selected text.
Similar script in JS:
http://pl.wikipedia.org/wiki/Wikipedysta:Nux/htag.js
(look for “htag.insert” function)
Extra:
Recognition of short tags:
case ‘img’:
case ‘meta’:
case ‘link’:
case ‘br’:
case ‘hr’:
case ‘input’:
Optional autocomplete for tags in the input would be great.
I’m not very Python friendly, but maybe some has something like that already (or can do it based on JS)?
|
 simon
Key Master
|
So this is a very basic implementation of what you’re looking for as a PN script. I don’t have time to add the extras, but hopefully you could do so based on this:
import pn, scintilla
@script("Surround With", "Xml")
def RecordedScript():
doc = pn.CurrentDoc()
sci = scintilla.Scintilla(doc)
text = sci.SelText
surround = pn.InputBox("HTML/XML Surround With", "Type the tag name...")
text = "<" + surround + ">" + text + "</" + surround + ">"
sci.ReplaceSel(str(text))
This needs modifying to ignore attributes, and to support short tags too.
|