Skip to content

Commit

Permalink
fix indentation in pre in preview
Browse files Browse the repository at this point in the history
Again, this is a dodgy hack: replace spaces with dot with the color
exactly like the background, because otherwise ST ignores it, even in
pre
  • Loading branch information
math2001 committed Nov 15, 2019
1 parent 6016f07 commit e3896a6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion MarkdownLivePreview.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def _update_preview(self, markdown_view):
resources
)

# print(html)
print(repr(html))

self.phantom_sets[markdown_view.id()].update([
sublime.Phantom(sublime.Region(0), html, sublime.LAYOUT_BLOCK,
Expand Down
4 changes: 3 additions & 1 deletion live-testing/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ what the hell...

```python
import this
# you should try this

if input("answer yes") != 'yes':
print("Really?")
```

this flickering is really annoying...
Expand Down
14 changes: 8 additions & 6 deletions markdown2html.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,17 @@ def markdown2html(markdown, basepath, re_render, resources):

# FIXME: how do tables look? should we use ascii tables?

# FIXME: pre aren't handled by ST3. The require manual adjustment

br = soup.new_tag('br')
# pre aren't handled by ST3. The require manual adjustment
for pre_element in soup.find_all('pre'):
# select the first child, <code>
code_element = next(pre_element.children)
# FIXME: this line sucks, but can we do better?
code_element.replace_with(
bs4.BeautifulSoup(str(code_element).replace('\n', '<br>'), "html.parser"))

# FIXME: this method sucks, but can we do better?
fixed_pre = str(code_element) \
.replace('\n', '<br>')\
.replace(' ', '<i class="space">.</i>')

code_element.replace_with(bs4.BeautifulSoup(fixed_pre, "html.parser"))

# FIXME: highlight the code using Sublime's syntax

Expand Down
3 changes: 3 additions & 0 deletions resources/stylesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ pre code {
padding: 0;
}

i.space {
color: var(--very-light-bg);
}

0 comments on commit e3896a6

Please sign in to comment.