Tag around selected text

Discussion Forums discussion Tag around selected text

This topic contains 0 voices and has 1 reply.

Viewing 2 posts - 1 through 2 (of 2 total)
Author Posts
Author Posts
August 12, 2010 at 2:54 pm #5070

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:

  1. Select text.
  2. Press some key (e.g. CTRL+SHIFT+T) → dialog with an input appears.
  3. Write tag name (and optional attrs after space).
  4. 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)?

August 19, 2010 at 10:43 am #17321

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.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.