Skip to content

Commit

Permalink
0.8.4 bug fixes (#329)
Browse files Browse the repository at this point in the history
* fix: Downgraded nodejs to version 16

* Revert "fix: Downgraded nodejs to version 16"

This reverts commit 816b86e.

* fix: Use nodejs 18 instead now

* ci: Fixed nodejs version in gh workflows

* fix: Improved the handling of [toc]

* feat: Supported to set env variables in paths

* fix: Always display the footer

* fix: Replaced uslug with another library

* fix: Fixed @import base64 encoding bug

* doc: Updated the changelog

* fix: Fixed another footer style

* fix: Fixed heading id generator
  • Loading branch information
shd101wyy authored Oct 10, 2023
1 parent ef2beb5 commit 2226a6a
Show file tree
Hide file tree
Showing 21 changed files with 171 additions and 89 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
- name: 'Install nodejs 20'
- name: 'Install nodejs 18'
uses: actions/setup-node@v3
with:
node-version: '20'
node-version: '18'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: 'Install nodejs 20'
- name: 'Install nodejs 18'
uses: actions/setup-node@v2
with:
node-version: '20'
node-version: '18'
- name: 'Build and test'
run: |
corepack enable
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/typedoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: 'Install nodejs 20'
- name: 'Install nodejs 18'
uses: actions/setup-node@v2
with:
node-version: '20'
node-version: '18'
- name: 'Build and test'
run: |
corepack enable
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ Please visit https://github.com/shd101wyy/vscode-markdown-preview-enhanced/relea

## [Unreleased]

## [0.8.24] - 2023-10-10

### Bug fixes

- Improved the handling of `[toc]`: https://github.com/shd101wyy/vscode-markdown-preview-enhanced/issues/1825
- Supported to set env variables in paths of configuration: https://github.com/shd101wyy/vscode-markdown-preview-enhanced/issues/1826
- Fixed the footer style: https://github.com/shd101wyy/vscode-markdown-preview-enhanced/issues/1822
- Fixed the bug of generating the header id: https://github.com/shd101wyy/vscode-markdown-preview-enhanced/issues/1827
- Fixed the bug of `@import` files that contains unicode characters: https://github.com/shd101wyy/vscode-markdown-preview-enhanced/issues/1823
- Now use node.js 18 for the project.

## [0.8.23] - 2023-10-10

### Bug fixes
Expand Down
5 changes: 4 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ module.exports = {
transform: {
'^.+\\.m?[tj]sx?$': 'ts-jest',
},
transformIgnorePatterns: ['/node_modules/(?!escape-string-regexp)'],
transformIgnorePatterns: [
// '/node_modules/(?!\@sindresorhus/slugify)',
// '/node_modules/(?!escape-string-regexp)',
],
roots: ['test'],
testMatch: ['**/?(*.)(spec|test).(j|t)s?(x)'],
testEnvironment: 'node',
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "crossnote",
"version": "0.8.23",
"version": "0.8.24",
"description": "A powerful markdown notebook tool",
"keywords": [
"markdown"
Expand All @@ -12,6 +12,9 @@
"kachkaev",
"gabyx"
],
"engines": {
"node": ">=18.0.0"
},
"exports": {
".": {
"import": "./out/esm/index.mjs",
Expand Down Expand Up @@ -136,6 +139,7 @@
"@types/react": "^18.2.21",
"@types/react-dom": "^18.2.7",
"@types/temp": "^0.9.1",
"@types/uslug": "^1.0.2",
"@types/vfile": "^3.0.2",
"@types/vscode": "1.80.0",
"@types/vscode-webview": "^1.57.2",
Expand Down
2 changes: 1 addition & 1 deletion shell.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ pkgs ? import <nixpkgs> { } }:
with pkgs;
mkShell {
buildInputs = [ nodejs_20 yarn ];
buildInputs = [ nodejs_18 yarn ];
shellHook = ''
# ...
'';
Expand Down
4 changes: 2 additions & 2 deletions src/converters/markdown-convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export async function markdownConvert(
useRelativeFilePath,
filesCache,
forPreview: false,
embeddingFilesInMarkdownDirectly: true,
usePandocParser: true, // NOTE: We need to set this to true here even though we don't use pandoc to parse the markdown.
forMarkdownExport: true,
protocolsWhiteListRegExp,
imageDirectoryPath,
Expand All @@ -263,7 +263,7 @@ export async function markdownConvert(
tab: ' ',
});
text = text.replace(
/^\s*\[CROSSNOTETOC\]\s*/gm,
/^\s*(?:<p[^>]*>)?<span>\[CROSSNOTETOC\]<\/span>(?:<\/p>)?\s*/gm,
'\n\n' + tocMarkdown + '\n\n',
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/converters/pandoc-convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ export async function pandocConvert(
filesCache,
protocolsWhiteListRegExp,
forPreview: false,
embeddingFilesInMarkdownDirectly: true,
usePandocParser: true,
notebook,
});
text = data.outputString;
Expand All @@ -414,7 +414,7 @@ export async function pandocConvert(
tab: ' ',
});
text = text.replace(
/^\s*\[CROSSNOTETOC\]\s*/gm,
/^\s*(?:<p[^>]*>)?<span>\[CROSSNOTETOC\]<\/span>(?:<\/p>)?\s*/gm,
'\n\n' + tocMarkdown + '\n\n',
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/custom-markdown-it-features/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ export default (md: MarkdownIt, notebook: Notebook) => {
if (token.children && token.children[0]?.content === '@embedding') {
const error = token.attrGet('error') ?? '';
if (error) {
return atob(error);
return decodeURIComponent(atob(error));
} else {
const embedding = token.attrGet('embedding') ?? '';
const decoded = atob(embedding);
const decoded = decodeURIComponent(atob(embedding));

if (
src &&
Expand Down
4 changes: 3 additions & 1 deletion src/markdown-engine/heading-id-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export default class HeadingIdGenerator {
.trim()
.replace(/~|/g, '') // sanitize
.replace(/``(.+?)``\s?/g, replacement)
.replace(/`(.*?)`\s?/g, replacement);
.replace(/`(.*?)`\s?/g, replacement)
.replace(/__(.+?)__\s?/g, replacement)
.replace(/_(.+?)_\s?/g, replacement);
let slug = uslug(heading.replace(/\s/g, '~')).replace(/~/g, '-');
if (this.table[slug] >= 0) {
this.table[slug] = this.table[slug] + 1;
Expand Down
63 changes: 31 additions & 32 deletions src/markdown-engine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2211,7 +2211,7 @@ sidebarTOCBtn.addEventListener('click', function(event) {
useRelativeFilePath: boolean,
) {
let slides = html.split(
/^\s*<p[^>]*><span>\[CROSSNOTESLIDE\]<\/span><\/p>\s*/gm,
/^\s*(?:<p[^>]*>)?<span>\[CROSSNOTESLIDE\]<\/span>(?:<\/p>)?\s*/gm,
);

const before = slides[0];
Expand Down Expand Up @@ -2302,7 +2302,7 @@ sidebarTOCBtn.addEventListener('click', function(event) {
`;
}

public async pandocRender(
private async pandocRender(
text: string = '',
args: string[],
): Promise<string> {
Expand Down Expand Up @@ -2335,7 +2335,7 @@ sidebarTOCBtn.addEventListener('click', function(event) {
let inCodeBlock = false;
let codeBlockSpacesAhead = 0;
while (i < lines.length) {
let line = lines[i];
const line = lines[i];
const match = line.match(/(^\s*)```/);
if (match) {
inCodeBlock = !inCodeBlock;
Expand Down Expand Up @@ -2369,10 +2369,6 @@ sidebarTOCBtn.addEventListener('click', function(event) {
continue;
}

if (line.match(/^\[toc\]/i) && !inCodeBlock) {
line = '[CROSSNOTETOC]';
}

outputString += line + '\n';
i += 1;
}
Expand Down Expand Up @@ -2437,13 +2433,8 @@ sidebarTOCBtn.addEventListener('click', function(event) {
}

// import external files and insert anchors if necessary
let outputString;
let slideConfigs;
let tocBracketEnabled;
let JSAndCssFiles;
let headings;
let frontMatterString;
({

let {
outputString,
// eslint-disable-next-line prefer-const
slideConfigs,
Expand All @@ -2458,12 +2449,12 @@ sidebarTOCBtn.addEventListener('click', function(event) {
fileDirectoryPath: options.fileDirectoryPath || this.fileDirectoryPath,
projectDirectoryPath: this.projectDirectoryPath.fsPath,
forPreview: options.isForPreview,
embeddingFilesInMarkdownDirectly: this.notebook.config.usePandocParser,
usePandocParser: this.notebook.config.usePandocParser,
protocolsWhiteListRegExp: this.protocolsWhiteListRegExp,
useRelativeFilePath: options.useRelativeFilePath,
filesCache: this.filesCache,
notebook: this.notebook,
}));
});

if (this.notebook.config.parserConfig['onDidTransformMarkdown']) {
outputString =
Expand Down Expand Up @@ -2511,7 +2502,6 @@ sidebarTOCBtn.addEventListener('click', function(event) {
}

args = this.notebook.config.pandocArguments.concat(args);

html = await this.pandocRender(outputString, args);
} catch (error) {
html = `<pre class="language-text"><code>${escape(
Expand Down Expand Up @@ -2542,27 +2532,36 @@ sidebarTOCBtn.addEventListener('click', function(event) {
const ordered = tocConfig['ordered'];

// Collaposible ToC
this.tocHTML = generateSidebarToCHTML(
headings,
this.notebook.md.render.bind(this.notebook.md),
{ ordered, depthFrom, depthTo, tab: ' ' },
);
// NOTE: We disable the source map here.
const sidebarTocMd = this.notebook.initMarkdownIt({
...this.notebook.md.options,
sourceMap: false,
});
this.tocHTML = generateSidebarToCHTML(headings, sidebarTocMd, {
ordered,
depthFrom,
depthTo,
tab: ' ',
});

// }
this.headings = headings; // reset headings information

if (tocBracketEnabled) {
// [TOC]
html = html.replace(/^\s*<p[^>]+>\[CROSSNOTETOC\]<\/p>\s*/gm, ($0) => {
// Check if $0 has `data-source-line` attribute
const match = $0.match(/data-source-line="(\d+)"/);
const lineNo = match ? match[1] : '';
if (lineNo) {
return `<div data-source-line="${lineNo}">${this.tocHTML}</div>`;
} else {
return this.tocHTML;
}
});
html = html.replace(
/^\s*(?:<p[^>]*>)?<span>\[CROSSNOTETOC\]<\/span>(?:<\/p>)?\s*/gm,
($0) => {
// Check if $0 has `data-source-line` attribute
const match = $0.match(/data-source-line="(\d+)"/);
const lineNo = match ? match[1] : '';
if (lineNo) {
return `<div data-source-line="${lineNo}">${this.tocHTML}</div>`;
} else {
return this.tocHTML;
}
},
);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/markdown-engine/toc.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import MarkdownIt from 'markdown-it';
import HeadingIdGenerator from './heading-id-generator';

function nPrefix(str, n) {
Expand Down Expand Up @@ -141,7 +142,7 @@ export function toc(headings: HeadingData[], opt: TocOption) {

export function generateSidebarToCHTML(
headings: HeadingData[],
mdRender: (md: string) => string,
md: MarkdownIt,
opt: TocOption,
): string {
if (!headings.length) {
Expand Down Expand Up @@ -217,7 +218,7 @@ export function generateSidebarToCHTML(
}px;`;
const paddingStyle = `padding:0;`;

const headingHtml = mdRender(heading.content);
const headingHtml = md.render(heading.content);
const headingId =
heading.id || headingIdGenerator.generateId(heading.content);
if (subHeadings.length) {
Expand Down
Loading

0 comments on commit 2226a6a

Please sign in to comment.