Skip to content

Commit

Permalink
feat: encapsuled styletag include workflow in vscode option
Browse files Browse the repository at this point in the history
The extension now supports an additional option, importStylesheetAsStyletag: if it set to true, the external user stylesheets added through vscode extension options are no longer merely referenced by a <ref>-tag, but rather their contents are included in <style>-tags so the html file doesn't break if the included stylesheets aren't present on the machine, thus improving shareability of the resulting html file.
  • Loading branch information
nifranz committed May 12, 2023
1 parent 3ae9aa5 commit 2842059
Show file tree
Hide file tree
Showing 3 changed files with 1,285 additions and 729 deletions.
12 changes: 8 additions & 4 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ function readStyles(uri) {
var i;

includeDefaultStyles = vscode.workspace.getConfiguration('markdown-pdf')['includeDefaultStyles'];
var includeStylesAsStyletag = vscode.workspace.getConfiguration('markdown-pdf')['importStylesheetAsStyletag'] || '';

// 1. read the style of the vscode.
if (includeDefaultStyles) {
Expand Down Expand Up @@ -709,10 +710,13 @@ function readStyles(uri) {
if (styles && Array.isArray(styles) && styles.length > 0) {
for (i = 0; i < styles.length; i++) {
var href = fixHref(uri, styles[i]);
// style += '<link rel=\"stylesheet\" href=\"' + href + '\" type=\"text/css\">';
var newpath = href.slice(7);
var tag = '<style>' + fs.readFileSync(newpath) + '</style>';
style += tag;
if (includeStylesAsStyletag) {
var newpath = href.slice(7);
var tag = '<style>' + fs.readFileSync(newpath) + '</style>';
style += tag;
} else {
style += '<link rel=\"stylesheet\" href=\"' + href + '\" type=\"text/css\">';
}
}
}

Expand Down

0 comments on commit 2842059

Please sign in to comment.