mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-21 09:38:01 +02:00
This commit is contained in:
parent
789d19b18c
commit
418a6e455f
@ -1291,6 +1291,7 @@ packages/renderer/MdToHtml/rules/mermaid.js
|
||||
packages/renderer/MdToHtml/rules/sanitize_html.js
|
||||
packages/renderer/MdToHtml/rules/source_map.js
|
||||
packages/renderer/MdToHtml/rules/tableHorizontallyScrollable.js
|
||||
packages/renderer/MdToHtml/rules/utils/defaultRule.js
|
||||
packages/renderer/MdToHtml/setupLinkify.js
|
||||
packages/renderer/MdToHtml/validateLinks.js
|
||||
packages/renderer/assetsToHeaders.js
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -1270,6 +1270,7 @@ packages/renderer/MdToHtml/rules/mermaid.js
|
||||
packages/renderer/MdToHtml/rules/sanitize_html.js
|
||||
packages/renderer/MdToHtml/rules/source_map.js
|
||||
packages/renderer/MdToHtml/rules/tableHorizontallyScrollable.js
|
||||
packages/renderer/MdToHtml/rules/utils/defaultRule.js
|
||||
packages/renderer/MdToHtml/setupLinkify.js
|
||||
packages/renderer/MdToHtml/validateLinks.js
|
||||
packages/renderer/assetsToHeaders.js
|
||||
|
@ -49,6 +49,8 @@ describe('MdToHtml', () => {
|
||||
checkboxRenderingType: 2,
|
||||
},
|
||||
};
|
||||
} else if (mdFilename.startsWith('sourcemap_')) {
|
||||
mdToHtmlOptions.mapsToLine = true;
|
||||
}
|
||||
|
||||
const markdown = await shim.fsDriver().readFile(mdFilePath);
|
||||
|
21
packages/app-cli/tests/md_to_html/sourcemap_table.html
Normal file
21
packages/app-cli/tests/md_to_html/sourcemap_table.html
Normal file
@ -0,0 +1,21 @@
|
||||
<div class="joplin-table-wrapper">
|
||||
<table class="maps-to-line" source-line="0" source-line-end="3">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>This</th>
|
||||
<th>is</th>
|
||||
<th>a</th>
|
||||
<th>test</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>This</td>
|
||||
<td>table</td>
|
||||
<td>has</td>
|
||||
<td>line numbers</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<p class="maps-to-line" source-line="4" source-line-end="5">When <code class="inline-code">mapsToLine</code> is enabled for this file, the table above should have line numbers that link to the original markdown.</p>
|
5
packages/app-cli/tests/md_to_html/sourcemap_table.md
Normal file
5
packages/app-cli/tests/md_to_html/sourcemap_table.md
Normal file
@ -0,0 +1,5 @@
|
||||
| This | is | a | test |
|
||||
|------|----|---|------|
|
||||
| This | table | has | line numbers |
|
||||
|
||||
When `mapsToLine` is enabled for this file, the table above should have line numbers that link to the original markdown.
|
@ -1,18 +1,21 @@
|
||||
import * as MarkdownIt from 'markdown-it';
|
||||
import type * as MarkdownIt from 'markdown-it';
|
||||
import type * as Renderer from 'markdown-it/lib/renderer';
|
||||
import defaultRule from './utils/defaultRule';
|
||||
|
||||
export default {
|
||||
// Make table horizontally scrollable by give table a div parent, so the width of the table is limited to the screen width.
|
||||
// see https://github.com/laurent22/joplin/pull/10161
|
||||
plugin: (markdownIt: MarkdownIt) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
||||
markdownIt.renderer.rules.table_open = function(tokens: MarkdownIt.Token[], idx: number, options: MarkdownIt.Options, _env: any, renderer: any) {
|
||||
const current = renderer.renderToken(tokens, idx, options);
|
||||
const defaultTableOpen = defaultRule(markdownIt, 'table_open');
|
||||
markdownIt.renderer.rules.table_open = function(tokens: MarkdownIt.Token[], idx: number, options: MarkdownIt.Options, env: unknown, renderer: Renderer) {
|
||||
const current = defaultTableOpen(tokens, idx, options, env, renderer);
|
||||
// joplin-table-wrapper css is set in packages/renderer/noteStyle.ts
|
||||
return `<div class="joplin-table-wrapper">\n${current}`;
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
||||
markdownIt.renderer.rules.table_close = function(tokens: MarkdownIt.Token[], idx: number, options: MarkdownIt.Options, _env: any, renderer: any) {
|
||||
const current = renderer.renderToken(tokens, idx, options);
|
||||
|
||||
const defaultTableClose = defaultRule(markdownIt, 'table_close');
|
||||
markdownIt.renderer.rules.table_close = function(tokens: MarkdownIt.Token[], idx: number, options: MarkdownIt.Options, env: unknown, renderer: Renderer) {
|
||||
const current = defaultTableClose(tokens, idx, options, env, renderer);
|
||||
return `${current}</div>\n`;
|
||||
};
|
||||
},
|
||||
|
9
packages/renderer/MdToHtml/rules/utils/defaultRule.ts
Normal file
9
packages/renderer/MdToHtml/rules/utils/defaultRule.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import type * as MarkdownIt from 'markdown-it';
|
||||
import type * as Renderer from 'markdown-it/lib/renderer';
|
||||
|
||||
const defaultRule = (markdownIt: MarkdownIt, key: keyof Renderer.RenderRuleRecord): Renderer.RenderRule => {
|
||||
if (markdownIt.renderer.rules[key]) return markdownIt.renderer.rules[key];
|
||||
return (tokens, idx, options, _env, renderer) => renderer.renderToken(tokens, idx, options);
|
||||
};
|
||||
|
||||
export default defaultRule;
|
Loading…
Reference in New Issue
Block a user