Skip to content

Commit 924989f

Browse files
committed
Bugfix and improved performance.
1 parent 2c61b34 commit 924989f

File tree

9 files changed

+97
-22
lines changed

9 files changed

+97
-22
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Changelog
22
=======
33

4+
### 1.0.5 (30)
5+
Bugfix:
6+
- Tag Filter extension fixed.
7+
- Improved performance for inline image handling in raw HTML fragment.
8+
- Better recognition of javascript fenced block.
9+
- Missing library credits on about dialog.
10+
411
### 1.0.4 (29)
512
New features:
613
- On macOS 12 Monterey, the new lightweight data based preview will be used.

QLMarkdown.xcodeproj/project.pbxproj

+8-8
Original file line numberDiff line numberDiff line change
@@ -1426,7 +1426,7 @@
14261426
CODE_SIGN_ENTITLEMENTS = QLExtension/QLExtension.entitlements;
14271427
CODE_SIGN_IDENTITY = "-";
14281428
CODE_SIGN_STYLE = Manual;
1429-
CURRENT_PROJECT_VERSION = 29;
1429+
CURRENT_PROJECT_VERSION = 30;
14301430
DEVELOPMENT_TEAM = "";
14311431
ENABLE_HARDENED_RUNTIME = NO;
14321432
HEADER_SEARCH_PATHS = (
@@ -1447,7 +1447,7 @@
14471447
"$(PROJECT_DIR)/re2",
14481448
);
14491449
MACOSX_DEPLOYMENT_TARGET = 10.15;
1450-
MARKETING_VERSION = 1.0.4;
1450+
MARKETING_VERSION = 1.0.5;
14511451
PRODUCT_BUNDLE_IDENTIFIER = org.sbarex.QLMarkdown.QLExtension;
14521452
PRODUCT_NAME = "$(TARGET_NAME)";
14531453
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -1464,7 +1464,7 @@
14641464
CODE_SIGN_ENTITLEMENTS = QLExtension/QLExtension.entitlements;
14651465
CODE_SIGN_IDENTITY = "-";
14661466
CODE_SIGN_STYLE = Manual;
1467-
CURRENT_PROJECT_VERSION = 29;
1467+
CURRENT_PROJECT_VERSION = 30;
14681468
DEVELOPMENT_TEAM = "";
14691469
ENABLE_HARDENED_RUNTIME = NO;
14701470
HEADER_SEARCH_PATHS = (
@@ -1485,7 +1485,7 @@
14851485
"$(PROJECT_DIR)/re2",
14861486
);
14871487
MACOSX_DEPLOYMENT_TARGET = 10.15;
1488-
MARKETING_VERSION = 1.0.4;
1488+
MARKETING_VERSION = 1.0.5;
14891489
PRODUCT_BUNDLE_IDENTIFIER = org.sbarex.QLMarkdown.QLExtension;
14901490
PRODUCT_NAME = "$(TARGET_NAME)";
14911491
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -1671,7 +1671,7 @@
16711671
CODE_SIGN_IDENTITY = "-";
16721672
CODE_SIGN_STYLE = Manual;
16731673
COMBINE_HIDPI_IMAGES = YES;
1674-
CURRENT_PROJECT_VERSION = 29;
1674+
CURRENT_PROJECT_VERSION = 30;
16751675
DEVELOPMENT_TEAM = "";
16761676
ENABLE_HARDENED_RUNTIME = NO;
16771677
FRAMEWORK_SEARCH_PATHS = (
@@ -1697,7 +1697,7 @@
16971697
"$(PROJECT_DIR)/re2",
16981698
);
16991699
MACOSX_DEPLOYMENT_TARGET = 10.15;
1700-
MARKETING_VERSION = 1.0.4;
1700+
MARKETING_VERSION = 1.0.5;
17011701
PRODUCT_BUNDLE_IDENTIFIER = org.sbarex.QLMarkdown;
17021702
PRODUCT_NAME = "$(TARGET_NAME)";
17031703
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -1718,7 +1718,7 @@
17181718
CODE_SIGN_IDENTITY = "-";
17191719
CODE_SIGN_STYLE = Manual;
17201720
COMBINE_HIDPI_IMAGES = YES;
1721-
CURRENT_PROJECT_VERSION = 29;
1721+
CURRENT_PROJECT_VERSION = 30;
17221722
DEVELOPMENT_TEAM = "";
17231723
ENABLE_HARDENED_RUNTIME = NO;
17241724
FRAMEWORK_SEARCH_PATHS = (
@@ -1744,7 +1744,7 @@
17441744
"$(PROJECT_DIR)/re2",
17451745
);
17461746
MACOSX_DEPLOYMENT_TARGET = 10.15;
1747-
MARKETING_VERSION = 1.0.4;
1747+
MARKETING_VERSION = 1.0.5;
17481748
PRODUCT_BUNDLE_IDENTIFIER = org.sbarex.QLMarkdown;
17491749
PRODUCT_NAME = "$(TARGET_NAME)";
17501750
PROVISIONING_PROFILE_SPECIFIER = "";

QLMarkdown/AboutViewController.swift

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class AboutViewController: NSViewController {
5656
s += "\(String(cString: get_lua_info()))<br />\n"
5757
s += "Enry (<a href=\"https://www.github.com/go-enry/go-enry/\">https://www.github.com/go-enry/go-enry</a>)<br />\n"
5858
s += "Google re2 (<a href=\"https://github.com/google/re2\">https://github.com/google/re2</a>)<br />\n"
59+
s += "Yams (<a href=\"https://github.com/jpsim/Yams.git\">https://github.com/jpsim/Yams.git</a>)<br />\n"
60+
s += "SwiftSoup (<a href=\"https://github.com/scinfu/SwiftSoup\">https://github.com/scinfu/SwiftSoup</a>)<br />\n"
5961
s += "<br />\n———<br />\n<br />\n"
6062
s += "Thanks to hazarek (<a href=\"https://github.com/hazarek\">https://github.com/hazarek</a>) for the app icon and CSS style.<br />\n"
6163

QLMarkdown/Settings.swift

+10-2
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,13 @@ class Settings {
497497
cmark_parser_free(parser)
498498
}
499499

500+
/*
501+
var extensions: UnsafeMutablePointer<cmark_llist>? = nil
502+
defer {
503+
cmark_llist_free(cmark_get_default_mem_allocator(), extensions)
504+
}
505+
*/
506+
500507
if self.tableExtension, let ext = cmark_find_syntax_extension("table") {
501508
cmark_parser_attach_syntax_extension(parser, ext)
502509
if let l = log {
@@ -506,6 +513,7 @@ class Settings {
506513
type: .debug
507514
)
508515
}
516+
// extensions = cmark_llist_append(cmark_get_default_mem_allocator(), nil, &ext)
509517
}
510518

511519
if self.autoLinkExtension, let ext = cmark_find_syntax_extension("autolink") {
@@ -696,7 +704,7 @@ class Settings {
696704

697705
let html_debug = self.renderDebugInfo(forAppearance: appearance, baseDir: baseDir)
698706
// Render
699-
if let html2 = cmark_render_html(doc, options, nil) {
707+
if let html2 = cmark_render_html(doc, options, cmark_parser_get_syntax_extensions(parser)) {
700708
defer {
701709
free(html2)
702710
}
@@ -968,7 +976,7 @@ table.debug td {
968976
</body>
969977
</html>
970978
"""
971-
if self.unsafeHTMLOption && self.inlineImageExtension {
979+
if self.unsafeHTMLOption && self.inlineImageExtension, let ext = cmark_find_syntax_extension("inlineimage"), cmark_syntax_extension_inlineimage_get_raw_images_count(ext) > 0 {
972980
var changed = false
973981
do {
974982
let doc = try SwiftSoup.parse(html, basedir.path)

TODO.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# TODO
22

3+
- [ ] Bugfix: on dark style, there is a flashing white rectangle before show the preview on Monterey.
34
- [ ] Investigate if export syntax highlighting colors scheme style as CSS var overriding the default style
45
- [ ] Syntax highlighting color scheme editor
56
- [ ] Check code signature and app group access
67
- [ ] Check inline images on network / mounted disk
78
- [ ] Investigate font family override for fanced blocks
89
- [ ] Localization support
9-
- [x] embed inline image for `<img>` raw tag without using javascript/callbacks.
10+
- [x] Embed inline image for `<img>` raw tag without using javascript/callbacks.
1011
- [x] Emoji extension: better code that parse the single placeholder and generate nodes inside the AST (this would avoid the CMARK_OPT_UNSAFE option for emojis as images)
1112
- [x] Investigate CMARK_OPT_UNSAFE for inline images
1213
- [x] Application screenshot in the docs

cmark-gfm/extensions/inlineimage.c

+46-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ typedef struct {
2626
char *path;
2727
MimeCheck *magic_callback;
2828
void *magic_context;
29+
int raw_images;
2930
} inlineimage_settings;
3031

3132
static inlineimage_settings *init_settings() {
@@ -34,6 +35,7 @@ static inlineimage_settings *init_settings() {
3435
settings->path = NULL;
3536
settings->magic_callback = NULL;
3637
settings->magic_context = NULL;
38+
settings->raw_images = 0;
3739
return settings;
3840
}
3941

@@ -48,6 +50,7 @@ static void release_settings(cmark_mem *mem, void *user_data)
4850
}
4951
settings->magic_callback = NULL;
5052
settings->magic_context = NULL;
53+
settings->raw_images = 0;
5154
mem->free(user_data);
5255
}
5356
}
@@ -197,6 +200,33 @@ char *cmark_syntax_extension_inlineimage_get_wd(cmark_syntax_extension *extensio
197200
return settings ? settings->path : NULL;
198201
}
199202

203+
int cmark_syntax_extension_inlineimage_get_raw_images_count(cmark_syntax_extension *ext) {
204+
inlineimage_settings *settings = (inlineimage_settings *)cmark_syntax_extension_get_private(ext);
205+
if (!settings) {
206+
settings = init_settings();
207+
cmark_syntax_extension_set_private(ext, settings, release_settings);
208+
}
209+
return settings->raw_images;
210+
}
211+
212+
void cmark_syntax_extension_inlineimage_set_raw_images_count(cmark_syntax_extension *ext, int value) {
213+
inlineimage_settings *settings = (inlineimage_settings *)cmark_syntax_extension_get_private(ext);
214+
if (!settings) {
215+
settings = init_settings();
216+
cmark_syntax_extension_set_private(ext, settings, release_settings);
217+
}
218+
settings->raw_images = value;
219+
}
220+
221+
void cmark_syntax_extension_inlineimage_increment_raw_images_count(cmark_syntax_extension *ext, int delta) {
222+
inlineimage_settings *settings = (inlineimage_settings *)cmark_syntax_extension_get_private(ext);
223+
if (!settings) {
224+
settings = init_settings();
225+
cmark_syntax_extension_set_private(ext, settings, release_settings);
226+
}
227+
settings->raw_images += delta;
228+
}
229+
200230
MimeCheck *cmark_syntax_extension_inlineimage_get_mime_callback(cmark_syntax_extension *extension)
201231
{
202232
inlineimage_settings *settings = (inlineimage_settings *)cmark_syntax_extension_get_private(extension);
@@ -227,13 +257,28 @@ void cmark_syntax_extension_inlineimage_set_mime_callback(cmark_syntax_extension
227257
settings->magic_context = context;
228258
}
229259

260+
static bool prefix(const char *pre, const char *str)
261+
{
262+
return strncmp(pre, str, strlen(pre)) == 0;
263+
}
264+
265+
static int filter(cmark_syntax_extension *ext, const unsigned char *tag,
266+
size_t tag_len) {
267+
if (prefix("<img ", (const char *)tag)) {
268+
cmark_syntax_extension_inlineimage_increment_raw_images_count(ext, 1);
269+
}
270+
271+
return 1;
272+
}
273+
230274
cmark_syntax_extension *create_inlineimage_extension(void) {
231275
cmark_syntax_extension *ext = cmark_syntax_extension_new("inlineimage");
232276

233277
inlineimage_settings *settings = init_settings();
234278
cmark_syntax_extension_set_private(ext, settings, release_settings);
235279

236280
cmark_syntax_extension_set_postprocess_func(ext, postprocess);
237-
281+
cmark_syntax_extension_set_html_filter_func(ext, filter);
282+
238283
return ext;
239284
}

cmark-gfm/extensions/inlineimage.h

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ cmark_syntax_extension *create_inlineimage_extension(void);
1616

1717
char *cmark_syntax_extension_inlineimage_get_wd(cmark_syntax_extension *extension);
1818
void cmark_syntax_extension_inlineimage_set_wd(cmark_syntax_extension *ext, const char *path);
19+
int cmark_syntax_extension_inlineimage_get_raw_images_count(cmark_syntax_extension *ext);
20+
void cmark_syntax_extension_inlineimage_set_raw_images_count(cmark_syntax_extension *ext, int value);
21+
void cmark_syntax_extension_inlineimage_increment_raw_images_count(cmark_syntax_extension *ext, int delta);
1922

2023
typedef char *(MimeCheck)( const char *filename, void *context );
2124

highlight-wrapper/wrapper_highlight.cpp

+18-9
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,12 @@ char *highlight_format_string2(const char *code, const char *language, int *exit
304304
outFilePath = "";
305305

306306
string suffix = language;
307-
if (suffix == "c++") {
308-
suffix = "cpp";
309-
} else if (suffix == "ascr" || suffix == "scpt") {
310-
suffix = "applescript";
311-
} else if (suffix == "plist" ) {
312-
suffix = "xml";
313-
} else if (suffix == "m" ) {
314-
suffix = "objc";
315-
} else if (suffix.front() == '{' && suffix.back() == '}') {
307+
// convert string to lower case
308+
std::for_each(suffix.begin(), suffix.end(), [](char & c){
309+
c = ::tolower(c);
310+
});
311+
312+
if (suffix.front() == '{' && suffix.back() == '}') {
316313
// remove r-markdown curly braces
317314
std::size_t found1 = suffix.find_first_of(','); // arguments separator
318315
std::size_t found2 = suffix.find_first_of(' ');
@@ -324,6 +321,18 @@ char *highlight_format_string2(const char *code, const char *language, int *exit
324321
suffix.erase(0, 1);
325322
}
326323
}
324+
325+
if (suffix == "c++") {
326+
suffix = "cpp";
327+
} else if (suffix == "ascr" || suffix == "scpt") {
328+
suffix = "applescript";
329+
} else if (suffix == "plist" ) {
330+
suffix = "xml";
331+
} else if (suffix == "m" ) {
332+
suffix = "objc";
333+
} else if (suffix == "javascript" ) {
334+
suffix = "js";
335+
}
327336
generator->setFilesCnt(1);
328337

329338
string getFallbackSyntax = "txt";

re2.xcodeproj/xcuserdata/sbaldiss.xcuserdatad/xcschemes/xcschememanagement.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<key>re2.xcscheme_^#shared#^_</key>
88
<dict>
99
<key>orderHint</key>
10-
<integer>3</integer>
10+
<integer>4</integer>
1111
</dict>
1212
</dict>
1313
</dict>

0 commit comments

Comments
 (0)