Sublime Forum

ST3: ExportHtml

#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

#21

[quote=“castles_made_of_sand”]https://github.com/sublimator/EditPreferences/blob/master/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 …[/quote]

Cool, I will take a look at your stuff. I would like to leverage the work of dealing with package paths instead of wasting time doing it all myself from scratch. I just dont have the motivation right now :smile:.

0 Likes

#22

hrmm, maybe between the 3 of us we can extract a module that works in all cases and isn’t too stupid inefficient

Packages/PackageName/Asset.ext
/Abspath/Packages/PackageName/Asset.ext
/Abspath/Packages/PackageName.sublime-package/Asset.ext

I guess each of these could somehow come from the following:

(sublime.packages_path(), sublime.installed_packages_path(), os.path.dirname(sublime.executable_path()))

I might start with extracting just path helper stuff into a new module/repo

0 Likes

#23

I’m doing some testing of it now. I’ll post here in a little bit. How I’m writing it now, you can return either the content of the file being searched for, or it will be extracted to a temp directory and the path will be returned.

0 Likes

#24

[pre=#0C1021]ST2 = sublime.version():1] == ‘2’
ST3 = not ST2
[/pre]

I got as far as declaring some constants, then went FUCK THIS, hahaha

Death to ST2 I say!

0 Likes

#25

Cool, I might take @faceless lead and sit this one out too :smile:

0 Likes

#26

Uploads the .pyc file to github Ha take that! :smiley: Alright I’d feel to mean doing that so that would never happen.

0 Likes

#27

[quote=“castles_made_of_sand”]
Cool, I might take @faceless lead and sit this one out too :smile:[/quote]

Sit’n is where it’s at :smile:.

0 Likes

#28

[quote=“facelessuser”]

[quote=“castles_made_of_sand”]
Cool, I might take @faceless lead and sit this one out too :smile:[/quote]

Sit’n is where it’s at :smile:.[/quote]

Here you go you sit’n…ers? :smiley: If you come across any issues or can think of any improvements, let me know.

gist.github.com/skuroda/4965913

0 Likes

#29

Sitting down @ linux-st3 land :smile:

0 Likes

#30

Looks good :smile:

Python 3 AFAIK seems to auto magically open(f).read() as unicode, defaulting to utf8

Defaulting to utf8 might not hurt, but having a possibility to consistently get bytes back might be nice …

0 Likes

#31

I think zipfile.ZipFile.read, on the other hand, will always return bytes, even on python 3?

0 Likes

#32
def get_package_asset(package_name, file_name, get_path=False):

I’d like to make a feature request ( bloody rich right?? :smile:

I want another helper that will get some arbitrary path and determine the pakage_name/file_name from it so I can feed it to the get_package_asset guy

[code]>>> import Default.sort

Default.sort.file
‘/home/nick/sublime_text_3/Packages/Default.sublime-package/sort.py’
[/code]

0 Likes

#33

[quote=“castles_made_of_sand”]def get_package_asset(package_name, file_name, get_path=False):

I’d like to make a feature request ( bloody rich right?? :smile:

I want another helper that will get some arbitrary path and determine the pakage_name/file_name from it so I can feed it to the get_package_asset guy

[code]>>> import Default.sort

Default.sort.file
‘/home/nick/sublime_text_3/Packages/Default.sublime-package/sort.py’
[/code][/quote]

I’ll take a look at the things you mentioned. If you insist, I suppose I will be a helpful developer and add that :smile:

0 Likes

#34

I really must insist :smile: I demand satisfaction haha

0 Likes