Home Download Buy Blog Forum Support

ST3: ExportHtml

Re: ST3: ExportHtml

Postby sublimator on Sat Feb 16, 2013 5:54 am

if bulletin_board:
# print css
bbcode = ["[pre=%s]" % dict(css[None]).get('background-color', '#000000')]
A = bbcode.append
from lxml.html import fromstring
import re

for txt in fromstring(html).xpath('//text()'):
if txt.is_tail or txt.is_text:
parent = txt.getparent()
if txt.is_tail: parent = parent.getparent()
style = None

while parent is not None:
style = parent.get('style')
if style: break
else: parent = parent.getparent()

color = re.search(r'(?<!background-)color:(#[A-Fa-f0-9]+)', parent.get('style'))
if color:
color = color.group(1)
else:
color = dict(css[None]).get('color', '#000000')

A("[color=%s]%s[/color]" % (color, txt))

html = "".join(bbcode + ["[/pre]"])
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am

Re: ST3: ExportHtml

Postby sublimator on Sat Feb 16, 2013 5:54 am

Ah, you did!

What are you doing there?
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am

Re: ST3: ExportHtml

Postby skuroda on Sat Feb 16, 2013 6:13 am

facelessuser wrote:Yeah, stuff like this takes the fun out of writing plugins. I really don't like doing coding gymnastics just to access a theme file.


If you don't want to do it , I know I have to to get at the keymap files. I'd be happy to share. Though you may already be working/finished it, but I just wanted to throw it out there.
skuroda
 
Posts: 676
Joined: Fri Oct 05, 2012 8:11 am

Re: ST3: ExportHtml

Postby facelessuser on Sat Feb 16, 2013 6:19 am

castles_made_of_sand wrote:( Did you ever find a way to allow bbcode tags as part of the bb export ?)


Not sure what you mean...but I do spit out bbcode...
facelessuser
 
Posts: 1542
Joined: Tue Apr 05, 2011 7:38 pm

Re: ST3: ExportHtml

Postby sublimator on Sat Feb 16, 2013 6:20 am

if bulletin_board:
# print css
bbcode = ["[pre=%s]" % dict(css[None]).get('background-color', '#000000')]
A
= bbcode.append
from lxml.html import fromstring
import re

TAG
= re.compile(r'(\[\w+|\[/\w+)', re.M | re.S)
def crude_tokenizer(text): # TODO: this would be a better algorithm for `inversion_stream`
"Yields"
last_end
= end = 0

for match in TAG.finditer(text):
start, end
= match.span()

if start != last_end:
yield text[last_end:start]

yield text[start:end]
last_end
= end

token_length
= len(text)

if end < token_length:
yield text[end:token_length]

for txt in fromstring(html).xpath('//text()'):
if txt.is_tail or txt.is_text:
parent
= txt.getparent()
if txt.is_tail: parent = parent.getparent()
style
= None

while parent is not None:
style
= parent.get('style')
if style: break
else: parent = parent.getparent()

color
= re.search(r'(?<!background-)color:(#[A-Fa-f0-9]+)', parent.get('style'))
if color:
color
= color.group(1)
else:
color
= dict(css[None]).get('color', '#000000')


color_wrap
= lambda t: "[color=%s]%s[/color]" % (color, t)

for t__ in crude_tokenizer(txt):
A(color_wrap(t__))

html
= "".join(bbcode + ["[/pre]"])


That seems to work, making sure to wrap any tag looking things in a bbcode element so as to break em up
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am

Re: ST3: ExportHtml

Postby facelessuser on Sat Feb 16, 2013 6:22 am

skuroda wrote:If you don't want to do it , I know I have to to get at the keymap files. I'd be happy to share. Though you may already be working/finished it, but I just wanted to throw it out there.


If you have something done, point me at it; I would love to save some time on this. I know roughly how I would approach it, but copying and pasting is even better ;) . I haven't bothered to touch this problem yet, I am just happy I finished porting all of my plugins.
facelessuser
 
Posts: 1542
Joined: Tue Apr 05, 2011 7:38 pm

Re: ST3: ExportHtml

Postby sublimator on Sat Feb 16, 2013 6:22 am

facelessuser wrote:Not sure what you mean...but I do spit out bbcode...


Yeah, one of the exports there was from your plugin ...

I just noticed mine was failing on exports that contained bbcode as part of the text ... so fixed it ...

Mine is just a ghetto hack to convert some <span style="$bla"> style html ...
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am

Re: ST3: ExportHtml

Postby facelessuser on Sat Feb 16, 2013 6:25 am

castles_made_of_sand wrote:
That seems to work, making sure to wrap any tag looking things in a bbcode element so as to break em up


Oh, you mean break up the bbcode tags? Yeah I can do that..

[pre=#151515][color=#CC99CC]def[/color][color=#6699CC] plugin_loaded[/color][color=#CCCCCC]([/color][color=#CCCCCC])[/color][color=#CCCCCC]:[/color]
[color=#CC99CC] global[/color][color=#CCCCCC] PLATFORM[/color]
[color=#CCCCCC] PLATFORM [/color][color=#66CCCC]=[/color][color=#CCCCCC] sublime.platform[/color][color=#CCCCCC]([/color][color=#CCCCCC])[/color]
[/pre]


Width wise it gets cut off if your browser isn't wide enough, but you get the idea.

Still not entirely sure what you are referring to though. Its late so maybe my brain isn't working.
facelessuser
 
Posts: 1542
Joined: Tue Apr 05, 2011 7:38 pm

Re: ST3: ExportHtml

Postby sublimator on Sat Feb 16, 2013 6:28 am

https://github.com/sublimator/EditPrefe ... helpers.py

I got some <em>crap<em> there for getting files ... not very coherent as it's first pass code as working through understanding ST3 implications ...

I had my own package globbing function which returns paths with /$Package.sublime-package/ if it's a zip file ...

Didn't really come across a case like today when getting a package normalised path from the api that doesn't `imply` much ...
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am

Re: ST3: ExportHtml

Postby sublimator on Sat Feb 16, 2013 6:29 am

Yeah, breaking up the bbcode tags so the content doesn't get parsed as markup by the forum ... and get all fucked up colors and missing content ...
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am

PreviousNext

Return to Plugin Announcements

Who is online

Users browsing this forum: Exabot [Bot] and 5 guests