Sublime Forum

ST3: ExportHtml

#1

Here is the initial port of ExportHtml to ST3 github.com/facelessuser/ExportHtml/tree/ST3

Seems to work fine, but report bugs here if they are found.

0 Likes

#2

Whatā€™s the speed like? Iā€™m guessing you are doing an arse load of match_selector calls?

Iā€™ve ported some plugins that had a lot of pt in range(n, m) forms that are drastically slower on ST3 :confused:

0 Likes

#3

I do do a number of score selectors, but not as many as you would think.

I grab the scope name from the selection and then compare all of the theme scopes with score_selector. Once I determine the best matches, I add the scope name with the best theme scope matches for foreground, background, etc. to the dictionary and never have to run score_selector on the same scope again.

I donā€™t notice much of a difference with the ST2 version and the ST3 version for this plugin.

0 Likes

#4

Ah, yes, of course the ranking would be memoized eh?

Ah, I guess I meant more the view.scope_name() thingy which you still have to do pt by pt eh.

Thatā€™s good to hear. Iā€™ve mainly only ran into annoyances when using pt by pt substr() stuff. I just assumed itā€™d be similar for other pt by pt.

0 Likes

#5

Yeah, there is no getting around that. But it seems fine.

0 Likes

#6

Traceback (most recent call last): File "/home/nick/.config/sublime-text-3/Packages/ExportHtml/ExportBbcode.py", line 38, in execute ExportBbcode(view).run(**self.args[value]) File "/home/nick/.config/sublime-text-3/Packages/ExportHtml/ExportBbcode.py", line 334, in run self.setup(**inputs) File "/home/nick/.config/sublime-text-3/Packages/ExportHtml/ExportBbcode.py", line 117, in setup self.plist_file = self.apply_filters(readPlist(path_packages + colour_scheme.replace('Packages', ''))) File "X/plistlib.py", line 73, in readPlist pathOrFile = open(pathOrFile, 'rb') FileNotFoundError: [Errno 2] No such file or directory: '/home/nick/.config/sublime-text-3/Packages/Color Scheme - Default/Blackboard.tmTheme'

Guess there is some issue with the now zipped package assets huh?

0 Likes

#7

Hmm. That is a problem. I use a non-default theme, so I didnā€™t notice or think about that. I will have to look into figuring out how to identify zipped assets and then unpack themā€¦arghā€¦

0 Likes

#8

What a pita eh ? I think Jon said heā€™s adding a resource api at some point.

You basically need to check the zip path which would be either in sublime.installed_packages() or near the executable_path()

Then itā€™s possible even if the zip is still there, that just one of the package assets has been overridden by a user.

The file path on the python files gets .sublime-package but things like view.settings().get(syntax|color_scheme) etc all leave you guessing.

0 Likes

#9

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.

0 Likes

#10

Just ported my ghetto version. Itā€™s about 10 times slower than before FFFFFFFF :confused:

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

[pre=#0C1021]if bulletin_board:
# print css
bbcode = ā€œ{pre=%s}ā€ % dict(cssNone]).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(cssNone]).get('color', '#000000')

        A("{color=%s}%s{/color}"  % (color, txt))

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

[/pre]

0 Likes

#11

[pre=#0C1021]if bulletin_board:
# print css
bbcode = ā€œ[pre=[/color]%s]ā€ % dict(cssNone]).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(cssNone]).get('color', '#000000')

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

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

#12

Ah, you did!

What are you doing there?

0 Likes

#13

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.

0 Likes

#14

Not sure what you meanā€¦but I do spit out bbcodeā€¦

0 Likes

#15

[pre=#0C1021]if bulletin_board:
# print css
bbcode = ā€œ[pre[/color]=%s]ā€ % dict(cssNone]).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[/color]:start]

        yield text[start[/color]:end]
        last_end = end

    token_length    = len(text)

    if end < token_length:
        yield text[end[/color]: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[/color]-Fa-f0-9]+)', parent.get('style'))
        if color:
            color = color.group(1)
        else:
            color = dict(cssNone]).get('color', '#000000')

        
        color_wrap = lambda t: "=%s]%s]"  % (color, t)
        
        for t__ in crude_tokenizer(txt):
            A(color_wrap(t__))

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

[/pre]

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

0 Likes

#16

[quote=ā€œskurodaā€]
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.[/quote]

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 :wink: . I havenā€™t bothered to touch this problem yet, I am just happy I finished porting all of my plugins.

0 Likes

#17

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 style html ā€¦

0 Likes

#18

[quote=ā€œcastles_made_of_sandā€]

That seems to work, making sure to wrap any tag looking things in a bbcode element so as to break em up[/quote]

Oh, you mean break up the bbcode tags? Yeah I can do thatā€¦

[pre=#151515]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][/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.

0 Likes

#19

github.com/sublimator/EditPrefe ā€¦ helpers.py

I got some crap 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 ā€¦

0 Likes

#20

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 ā€¦

0 Likes