mirror of
https://github.com/danbulant/lezer-markdown-obsidian
synced 2026-06-21 15:41:56 +00:00
Compare commits
No commits in common. "main" and "0.0.2" have entirely different histories.
6 changed files with 32 additions and 61 deletions
21
LICENSE
21
LICENSE
|
|
@ -1,21 +0,0 @@
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2023 Eric Rykwalder
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
10
README.md
10
README.md
|
|
@ -29,14 +29,10 @@ import { Comment, InternalLink } from "lezer-markdown-obsidian";
|
||||||
const parser = mdParser.configure([Comment, InternalLink]);
|
const parser = mdParser.configure([Comment, InternalLink]);
|
||||||
```
|
```
|
||||||
|
|
||||||
### `Extensions`
|
### `ObsidianMDExtensions`
|
||||||
|
|
||||||
An array of all the extensions for Obsidian's markdown syntax.
|
An array of all the extensions for Obsidian's markdown syntax.
|
||||||
|
|
||||||
### `BlockAndInline`
|
|
||||||
|
|
||||||
An array of all the extensions except YAML frontmatter.
|
|
||||||
|
|
||||||
### `Comment`
|
### `Comment`
|
||||||
|
|
||||||
This adds support for parsing comments in the form of: `%%comment%%`.
|
This adds support for parsing comments in the form of: `%%comment%%`.
|
||||||
|
|
@ -77,10 +73,6 @@ Internal embeds are structured like:
|
||||||
|
|
||||||
The `#heading` and `|display` parts are optional. Heading can be a `#^blockid` instead, and multiple headings can be chained together.
|
The `#heading` and `|display` parts are optional. Heading can be a `#^blockid` instead, and multiple headings can be chained together.
|
||||||
|
|
||||||
### `Mark`
|
|
||||||
|
|
||||||
This adds support for highlight marks in the form of `==highlighted==`.
|
|
||||||
|
|
||||||
### `TaskList`
|
### `TaskList`
|
||||||
|
|
||||||
This adds support for Obsidian's task lists, which allow support for arbitrary characters for tasks. This makes it different from GFM task lists.
|
This adds support for Obsidian's task lists, which allow support for arbitrary characters for tasks. This makes it different from GFM task lists.
|
||||||
|
|
|
||||||
4
package-lock.json
generated
4
package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "lezer-markdown-obsidian",
|
"name": "lezer-markdown-obsidian",
|
||||||
"version": "0.0.3",
|
"version": "0.0.2",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "lezer-markdown-obsidian",
|
"name": "lezer-markdown-obsidian",
|
||||||
"version": "0.0.3",
|
"version": "0.0.2",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lezer/common": "^0.15.11",
|
"@lezer/common": "^0.15.11",
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "lezer-markdown-obsidian",
|
"name": "lezer-markdown-obsidian",
|
||||||
"description": "Obsidian Markdown extensions for @lezer/markdown",
|
"description": "Obsidian Markdown extensions for @lezer/markdown",
|
||||||
"version": "0.0.3",
|
"version": "0.0.2",
|
||||||
"main": "dist/index.cjs",
|
"main": "dist/index.cjs",
|
||||||
"module": "dist/index.js",
|
"module": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,6 @@ declare module "@lezer/markdown" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const CommentDelim = { resolve: "Comment", mark: "CommentMarker" };
|
|
||||||
|
|
||||||
export const Comment: MarkdownConfig = {
|
export const Comment: MarkdownConfig = {
|
||||||
defineNodes: ["Comment", "CommentMarker"],
|
defineNodes: ["Comment", "CommentMarker"],
|
||||||
parseBlock: [
|
parseBlock: [
|
||||||
|
|
@ -68,17 +66,18 @@ export const Comment: MarkdownConfig = {
|
||||||
{
|
{
|
||||||
name: "CommentInline",
|
name: "CommentInline",
|
||||||
parse(cx: InlineContext, next: number, pos: number) {
|
parse(cx: InlineContext, next: number, pos: number) {
|
||||||
if (next == 37 && cx.char(pos + 1) == 37) {
|
let match = /^%%[^\n]*[^\n\\]%%/.exec(cx.text.slice(pos - cx.offset));
|
||||||
let canClose = true;
|
if (!match) {
|
||||||
if (
|
return -1;
|
||||||
cx.slice(cx.offset, pos).lastIndexOf("\n") >
|
|
||||||
cx.slice(cx.offset, pos).lastIndexOf("%%")
|
|
||||||
) {
|
|
||||||
canClose = false;
|
|
||||||
}
|
|
||||||
return cx.addDelimiter(CommentDelim, pos, pos + 2, true, canClose);
|
|
||||||
}
|
}
|
||||||
return -1;
|
const start = pos;
|
||||||
|
const end = pos + match[0].length;
|
||||||
|
return cx.addElement(
|
||||||
|
cx.elt("Comment", start, end, [
|
||||||
|
cx.elt("CommentMarker", start, start + 2),
|
||||||
|
cx.elt("CommentMarker", end - 2, end),
|
||||||
|
])
|
||||||
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
@ -340,7 +339,7 @@ function parseDisplay(cx: InlineContext, start: number): Element | null {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MarkDelim = { resolve: "Mark", mark: "MarkMarker" };
|
const MarkDelim = { resolve: "Mark", mark: "MarkMarker" };
|
||||||
|
|
||||||
export const Mark: MarkdownConfig = {
|
export const Mark: MarkdownConfig = {
|
||||||
defineNodes: ["Mark", "MarkMarker"],
|
defineNodes: ["Mark", "MarkMarker"],
|
||||||
|
|
@ -397,8 +396,6 @@ export const TaskList: MarkdownConfig = {
|
||||||
};
|
};
|
||||||
/* End Copyright */
|
/* End Copyright */
|
||||||
|
|
||||||
const TexDelim = { resolve: "TexInline", mark: "TexMarker" };
|
|
||||||
|
|
||||||
export const Tex: MarkdownConfig = {
|
export const Tex: MarkdownConfig = {
|
||||||
defineNodes: ["TexBlock", "TexInline", "TexMarker"],
|
defineNodes: ["TexBlock", "TexInline", "TexMarker"],
|
||||||
parseBlock: [
|
parseBlock: [
|
||||||
|
|
@ -446,15 +443,21 @@ export const Tex: MarkdownConfig = {
|
||||||
parseInline: [
|
parseInline: [
|
||||||
{
|
{
|
||||||
name: "TexInline",
|
name: "TexInline",
|
||||||
parse(cx: InlineContext, next: number, pos: number) {
|
parse(cx: InlineContext, _, pos: number) {
|
||||||
if (next != 36 /* $ */) {
|
let match = /^\$(?:[^$\t ][^$]*)?[^$\t \\]\$(\D|$)/.exec(
|
||||||
|
cx.text.slice(pos - cx.offset)
|
||||||
|
);
|
||||||
|
if (!match) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
const before = cx.slice(pos - 1, pos);
|
const start = pos;
|
||||||
const after = cx.slice(pos + 1, pos + 2);
|
const end = start + match[0].length - match[1].length;
|
||||||
const canClose = /[^ \t]/.test(before) && !/\d/.test(after);
|
return cx.addElement(
|
||||||
const canOpen = /[^$ \t]/.test(after);
|
cx.elt("TexInline", start, end, [
|
||||||
return cx.addDelimiter(TexDelim, pos, pos + 1, canOpen, canClose);
|
cx.elt("TexMarker", start, start + 1),
|
||||||
|
cx.elt("TexMarker", end - 1, end),
|
||||||
|
])
|
||||||
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
@ -493,7 +496,7 @@ export const YAMLFrontMatter: MarkdownConfig = {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Extensions = [
|
export const ObsidianMDExtensions = [
|
||||||
Comment,
|
Comment,
|
||||||
Footnote,
|
Footnote,
|
||||||
Hashtag,
|
Hashtag,
|
||||||
|
|
@ -506,6 +509,4 @@ export const Extensions = [
|
||||||
YAMLFrontMatter,
|
YAMLFrontMatter,
|
||||||
];
|
];
|
||||||
|
|
||||||
export const BlockAndInline = Extensions.slice(0, -1);
|
export const parser = defParser.configure(ObsidianMDExtensions);
|
||||||
|
|
||||||
export const parser = defParser.configure(Extensions);
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
export {
|
export {
|
||||||
BlockAndInline,
|
|
||||||
Comment,
|
Comment,
|
||||||
Extensions,
|
|
||||||
Footnote,
|
Footnote,
|
||||||
Hashtag,
|
Hashtag,
|
||||||
InternalLink,
|
InternalLink,
|
||||||
Mark,
|
Mark,
|
||||||
|
ObsidianMDExtensions,
|
||||||
parser,
|
parser,
|
||||||
TaskList,
|
TaskList,
|
||||||
Tex,
|
Tex,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue