Compare commits

...

30 Commits

Author SHA1 Message Date
afa554b52b Merge branch 'master' of git.0x42.cloud:christian.morpurgo/MarkdownLivePreview 2025-04-24 17:06:49 +02:00
e0daa147f1 fix import 2025-04-24 17:06:45 +02:00
f3cd6d3fcf Update repository.json 2025-04-24 15:04:58 +00:00
0034602fff new build 2025-04-24 17:04:04 +02:00
b29d054de2 new build 2025-04-24 16:49:41 +02:00
a9f2f951c0 update repo 2025-04-24 16:42:21 +02:00
696eb1e1dd new build 2025-04-24 16:41:00 +02:00
6379b673fc fix imports 2025-04-24 16:40:24 +02:00
b521caed0f new build 2025-04-24 16:38:39 +02:00
9bcd725a41 new build added 2025-04-24 16:37:26 +02:00
aec40dcf2f remove old package 2025-04-24 16:33:56 +02:00
b25ab1a4c6 Merge branch 'master' of git.0x42.cloud:christian.morpurgo/MarkdownLivePreview 2025-04-24 16:32:31 +02:00
243555c0c9 change imports move libraries into lib 2025-04-24 16:32:24 +02:00
40da1972af Delete dependencies.json 2025-04-24 14:18:49 +00:00
af7b054d5d Update repository.json 2025-04-24 14:16:27 +00:00
4d3c2a7139 Update repository.json 2025-04-24 14:05:29 +00:00
06d45e51b9 archive 2025-04-24 16:03:43 +02:00
0ddc896fc3 Merge branch 'master' of git.0x42.cloud:christian.morpurgo/MarkdownLivePreview 2025-04-24 16:03:09 +02:00
6f488e0d64 Update repository.json 2025-04-24 13:35:51 +00:00
4eed4934ff Update repository.json 2025-04-24 13:30:58 +00:00
626793e31d Update repository.json 2025-04-24 13:22:41 +00:00
c5493db292 Update repository.json 2025-04-24 13:18:10 +00:00
e6b028506b Update repository.json 2025-04-24 13:11:23 +00:00
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
30 changed files with 47 additions and 20 deletions

View File

@ -1,3 +1,22 @@
import os
import sys
import sublime
# Add the package archive path itself to sys.path
package_path = os.path.dirname(__file__)
if package_path not in sys.path:
sys.path.insert(0, package_path)
# --- Add lib to sys.path ---
# Get the directory containing this file (MarkdownLivePreview.py)
plugin_dir = os.path.dirname(__file__)
# Construct the absolute path to the 'lib' directory
lib_path = os.path.join(plugin_dir, 'lib')
# Add it to the beginning of sys.path if it's not already there
if lib_path not in sys.path:
sys.path.insert(0, lib_path)
# --- End sys.path modification ---
"""
Terminology
original_view: the view in the regular editor, without it's own window
@ -8,9 +27,7 @@ preview_window: the window with the markdown file and the preview
"""
import time
import os.path
import struct
import sublime
import sublime_plugin
from functools import partial

Binary file not shown.

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

@ -1,7 +0,0 @@
{
"*": {
"*": [
"bs4"
]
}
}

View File

@ -11,14 +11,18 @@ import os.path
import concurrent.futures
import urllib.request
import base64
import bs4
# --- Bundled library imports ---
# Explicitly import from the 'lib' directory, now that the package root is in sys.path
from lib import bs4
from lib.markdown2 import Markdown
# --- End bundled library imports ---
from functools import partial
from .lib.markdown2 import Markdown
__all__ = ("markdown2html",)
# Use the imported module name
markdowner = Markdown(extras=["fenced-code-blocks", "cuddled-lists"])
# FIXME: how do I choose how many workers I want? Does thread pool reuse threads or
@ -33,6 +37,7 @@ def markdown2html(markdown, basepath, re_render, resources, viewport_width, font
"""
html = markdowner.convert(markdown)
# Use the imported module name
soup = bs4.BeautifulSoup(html, "html.parser")
for img_element in soup.find_all("img"):
src = img_element["src"]
@ -52,14 +57,15 @@ def markdown2html(markdown, basepath, re_render, resources, viewport_width, font
# realpath: simplify that paths so that we don't have duplicated caches
path = os.path.realpath(os.path.expanduser(os.path.join(basepath, src)))
base64, (width, height) = get_base64_image(path, re_render, resources)
base64_img, (width, height) = get_base64_image(path, re_render, resources) # Renamed local var to avoid conflict
img_element["src"] = base64
img_element["src"] = base64_img
if width > viewport_width:
img_element["width"] = viewport_width
img_element["height"] = viewport_width * (height / width)
# remove comments, because they pollute the console with error messages
# Use the imported module name
for comment_element in soup.find_all(
text=lambda text: isinstance(text, bs4.Comment)
):
@ -78,7 +84,7 @@ def markdown2html(markdown, basepath, re_render, resources, viewport_width, font
.replace(" ", '<i class="space">.</i>')
.replace("\n", "<br />")
)
# Use the imported module name
code_element.replace_with(bs4.BeautifulSoup(fixed_pre, "html.parser"))
# FIXME: highlight the code using Sublime's syntax

View File

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