Compare commits

..

12 Commits

Author SHA1 Message Date
2973f7f138 Update repository.json 2025-04-24 12:41:55 +00:00
2a58c22160 Update repository.json 2025-04-24 12:41:44 +00:00
beb6cfe709 Update repository.json 2025-04-24 12:33:51 +00:00
44eb19d923 Update repository.json 2025-04-24 12:32:30 +00:00
0354ddf41d Add channel.json 2025-04-24 12:30:54 +00:00
fede6c2873 Update repository.json 2025-04-24 12:29:18 +00:00
141a7d062c Update repository.json 2025-04-24 12:25:46 +00:00
2365d6fec2 Merge branch 'master' of git.0x42.cloud:christian.morpurgo/MarkdownLivePreview 2025-04-24 14:19:26 +02:00
35c8a954d0 add feature:
setting to increase font scale
2025-04-24 14:18:29 +02:00
e914a2d4e9 Update repository.json 2025-04-24 12:13:14 +00:00
7fbb23b480 Add repository.json 2025-04-24 12:12:04 +00:00
ec27d980a3 meta: add known limitation about ordered lists #97
Sublime Text renders ordered lists as unordered lists. I've only added it to the README.md for now, because I'm not sure about how the GitHub website and README should sync...
2019-12-05 07:35:27 +11:00
6 changed files with 71 additions and 7 deletions

View File

@ -20,6 +20,7 @@ from .markdown2html import markdown2html
MARKDOWN_VIEW_INFOS = "markdown_view_infos" MARKDOWN_VIEW_INFOS = "markdown_view_infos"
PREVIEW_VIEW_INFOS = "preview_view_infos" PREVIEW_VIEW_INFOS = "preview_view_infos"
SETTING_DELAY_BETWEEN_UPDATES = "delay_between_updates" SETTING_DELAY_BETWEEN_UPDATES = "delay_between_updates"
SETTING_FONT_SCALE = "font_scale"
resources = {} resources = {}
@ -201,7 +202,12 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener):
# This check is needed since a this function is used as a callback for when images # This check is needed since a this function is used as a callback for when images
# are loaded from the internet (ie. it could finish loading *after* the user # are loaded from the internet (ie. it could finish loading *after* the user
# closes the markdown_view) # closes the markdown_view)
if time.time() - self.last_update < DELAY / 1000: # Reload settings each time to catch changes
settings = get_settings()
delay = settings.get(SETTING_DELAY_BETWEEN_UPDATES, 100) # Provide default
font_scale = settings.get(SETTING_FONT_SCALE, 1.0) # Provide default
if time.time() - self.last_update < delay / 1000:
return return
if markdown_view.buffer_id() == 0: if markdown_view.buffer_id() == 0:
@ -213,15 +219,19 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener):
markdown = markdown_view.substr(total_region) markdown = markdown_view.substr(total_region)
preview_view = markdown_view.window().active_view_in_group(1) preview_view = markdown_view.window().active_view_in_group(1)
viewport_width = preview_view.viewport_extent()[0] # Get viewport_width, default to a large value if view isn't ready
viewport_extent = preview_view.viewport_extent()
viewport_width = viewport_extent[0] if viewport_extent else 1024
basepath = os.path.dirname(markdown_view.file_name())
basepath = os.path.dirname(markdown_view.file_name()) if markdown_view.file_name() else '.' # Handle unsaved files
html = markdown2html( html = markdown2html(
markdown, markdown,
basepath, basepath,
partial(self._update_preview, markdown_view), partial(self._update_preview, markdown_view),
resources, resources,
viewport_width, viewport_width,
font_scale,
) )
self.phantom_sets[markdown_view.id()].update( self.phantom_sets[markdown_view.id()].update(

View File

@ -1,4 +1,7 @@
{ {
// minimum number of milliseconds to wait before updating the preview again // minimum number of milliseconds to wait before updating the preview again
"delay_between_updates": 100 "delay_between_updates": 100,
// scale factor for the font size relative to markdown settings
"font_scale": 1.0
} }

View File

@ -42,4 +42,24 @@ $ grep -R FIXME
2. Make your own branch (the name of the branch should be the feature you are 2. Make your own branch (the name of the branch should be the feature you are
implementing eg. `improve-tables`, `fix-crash-on-multiple-preview` implementing eg. `improve-tables`, `fix-crash-on-multiple-preview`
3. All your code should be formated by black. 3. All your code should be formated by black.
4. Send a PR! 4. Send a PR!
### Known limitations
#### Numbered lists are rendered as unordered lists
```md
1. first
2. second
3. third
```
will be previewed the exact same way as
```md
- first
- second
- third
```
The issue comes from [Sublime Text's minihtml](https://www.sublimetext.com/docs/3/minihtml.html) which [doesn't support ordered lists](https://github.com/sublimehq/sublime_text/issues/1767). If you think feel like implementing a workaround, feel free to contribute, but it's not something I'm planning on doing. It isn't a critical feature, and support should come with time...

7
channel.json Normal file
View File

@ -0,0 +1,7 @@
{
"$schema": "sublime://packagecontrol.io/schemas/channel",
"schema_version": "4.0.0",
"repositories": [
"https://git.0x42.cloud/christian.morpurgo/MarkdownLivePreview/raw/branch/master/repository.json"
]
}

View File

@ -25,7 +25,7 @@ markdowner = Markdown(extras=["fenced-code-blocks", "cuddled-lists"])
# does it stupidly throw them out? (we could implement something of our own) # does it stupidly throw them out? (we could implement something of our own)
executor = concurrent.futures.ThreadPoolExecutor(max_workers=5) executor = concurrent.futures.ThreadPoolExecutor(max_workers=5)
def markdown2html(markdown, basepath, re_render, resources, viewport_width): def markdown2html(markdown, basepath, re_render, resources, viewport_width, font_scale=1.0):
""" converts the markdown to html, loads the images and puts in base64 for sublime """ converts the markdown to html, loads the images and puts in base64 for sublime
to understand them correctly. That means that we are responsible for loading the to understand them correctly. That means that we are responsible for loading the
images from the internet. Hence, we take in re_render, which is just a function we images from the internet. Hence, we take in re_render, which is just a function we
@ -84,7 +84,11 @@ def markdown2html(markdown, basepath, re_render, resources, viewport_width):
# FIXME: highlight the code using Sublime's syntax # FIXME: highlight the code using Sublime's syntax
# FIXME: report that ST doesn't support <br/> but does work with <br />... WTF? # FIXME: report that ST doesn't support <br/> but does work with <br />... WTF?
return "<style>\n{}\n</style>\n\n{}".format(resources["stylesheet"], soup).replace( # Add font scaling CSS rule
font_scale_css = "body {{ font-size: {}em; }}\n".format(font_scale)
stylesheet = font_scale_css + resources["stylesheet"]
return "<style>\n{}\n</style>\n\n{}".format(stylesheet, soup).replace(
"<br/>", "<br />" "<br/>", "<br />"
) )
@ -218,4 +222,5 @@ def independent_markdown2html(markdown):
"stylesheet": "", "stylesheet": "",
}, },
960, 960,
1.0, # Add default font_scale for independent call
) )

19
repository.json Normal file
View File

@ -0,0 +1,19 @@
{
"schema_version": "3.0.0",
"packages": [
{
"name": "MarkdownLivePreview-Fork",
"description": "My enhanced live-preview fork of MarkdownLivePreview",
"author": "Christian Morpurgo",
"homepage": "https://git.0x42.cloud/christian.morpurgo/MarkdownLivePreview",
"releases": [
{
"version": "4.0.0",
"url": "https://git.0x42.cloud/christian.morpurgo/MarkdownLivePreview/archive/v4.0.0.zip",
"date": "2025-04-24 00:00:00",
"sublime_text": "*"
}
]
}
]
}