-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
021f4be
commit 23271e0
Showing
14 changed files
with
667 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import * as md from "../../mod.ts"; | ||
import * as html from "@lambdaurora/libhtml"; | ||
import * as md from "../../mod.ts"; | ||
import katex from "https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.mjs"; // For inline LaTeX rendering | ||
|
||
if (Deno.args.length !== 1) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,27 +5,28 @@ import Prism from "https://cdn.jsdelivr.net/npm/[email protected]/prism.min.js"; | |
await fetch("./example.md") | ||
.then(response => { | ||
if (!response.ok) { | ||
throw new Error('Network response was not ok'); | ||
throw new Error("Network response was not ok"); | ||
} | ||
return response.text(); | ||
}) | ||
.then(text => { | ||
let doc = md.parser.parse(text, {latex: false}); | ||
let doc = md.parser.parse(text, { latex: false }); | ||
md.render_to_dom(doc, document, { | ||
block_code: { | ||
highlighter: (code, language, parent) => { | ||
if ((Prism.languages as any)[language]) { | ||
const stuff = html.parse( | ||
`<pre><code>${Prism.highlight(code, (Prism.languages as any)[language], language)}</code></pre>` | ||
`<pre><code>${Prism.highlight(code, (Prism.languages as any)[language], language)}</code></pre>`, | ||
) as html.Element; | ||
parent.children = stuff.get_element_by_tag_name("code")!.children; | ||
} else | ||
} else { | ||
parent.append_child(new html.Text(code)); | ||
} | ||
} | ||
}, | ||
}, | ||
image: {class_name: "responsive_img"}, | ||
spoiler: {enable: true}, | ||
parent: document.querySelector("main") | ||
image: { class_name: "responsive_img" }, | ||
spoiler: { enable: true }, | ||
parent: document.querySelector("main"), | ||
}); | ||
|
||
document.querySelectorAll(".spoiler_hidden").forEach(spoiler => { | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// deno-lint-ignore-file no-explicit-any | ||
/* | ||
* Copyright 2024 LambdAurora <[email protected]> | ||
* | ||
|
@@ -8,9 +9,9 @@ | |
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import * as md from "./tree/index.ts"; | ||
import * as html from "@lambdaurora/libhtml"; | ||
import { HTML_TAGS_TO_PURGE_SUGGESTION, is_whitespace, purge_inline_html } from "../utils.ts"; | ||
import * as md from "./tree/index.ts"; | ||
import { HTML_TAGS_TO_PURGE_SUGGESTION, is_whitespace, purge_inline_html } from "./utils.ts"; | ||
|
||
/** | ||
* Represents the parser options related to code elements. | ||
|
@@ -325,7 +326,7 @@ function try_parse_url(input: string, start: number) { | |
* @param start the tag start index | ||
* @param delimiter the tag delimiter (1 character) | ||
* @param delimiter_repeat how many times the tag delimiter character is repeated to form the delimiter | ||
* @return an object if the tag has been parsed successfully, else `null` | ||
* @returns an object if the tag has been parsed successfully, else `null` | ||
*/ | ||
function try_parse_tag(text: string, start: number, delimiter: string, delimiter_repeat: number) { | ||
const rest = text.substring(start); | ||
|
@@ -383,11 +384,12 @@ function try_parse_tag(text: string, start: number, delimiter: string, delimiter | |
|
||
/** | ||
* Tries to parse a single tag by parsing with different delimiters through decreasing the delimiter repeat until a match is found. | ||
* | ||
* @param text the text to parse | ||
* @param start the tag start index | ||
* @param {string} delimiter the tag delimiter (1 character) | ||
* @param {number} delimiter_repeat how many times the tag delimiter character is repeated to form the delimiter for the first iteration | ||
* @return an object if the tag has been parsed successfully, or `null` otherwise | ||
* @param delimiter the tag delimiter (1 character) | ||
* @param delimiter_repeat how many times the tag delimiter character is repeated to form the delimiter for the first iteration | ||
* @returns an object if the tag has been parsed successfully, or `null` otherwise | ||
*/ | ||
function try_parse_possible_tags(text: string, start: number, delimiter: string, delimiter_repeat: number) { | ||
for (let i = delimiter_repeat; i > 0; i--) { | ||
|
@@ -399,7 +401,7 @@ function try_parse_possible_tags(text: string, start: number, delimiter: string, | |
return null; | ||
} | ||
|
||
function is_html_tag_allowed(tag: string, options: ParserOptions) { | ||
function is_html_tag_allowed(tag: string, options: ParserOptions): boolean { | ||
return !options.inline_html.disallowed_tags?.includes(tag); | ||
} | ||
|
||
|
@@ -493,7 +495,7 @@ function create_quote(block: BlockGroup, context: ParsingContext): md.BlockQuote | |
* Parses a Markdown document from the given string. | ||
* | ||
* @param string the Markdown source | ||
* @param options the parser options | ||
* @param options the parsing options | ||
* @returns the parsed Markdown document | ||
*/ | ||
export function parse(string: string, options: Partial<ParserOptions> = {}): md.Document { | ||
|
@@ -790,31 +792,10 @@ function parse_block(block: BlockGroup, context: ParsingContext): md.BlockElemen | |
return new md.Comment(block.block.replace(/^\s*<!-?-?/, "")); | ||
case "heading": { | ||
// Heading | ||
let nodes = block.block.split(" "); | ||
let level; | ||
switch (nodes[0].length) { | ||
case 1: | ||
level = md.HeadingLevel.H1; | ||
break; | ||
case 2: | ||
level = md.HeadingLevel.H2; | ||
break; | ||
case 3: | ||
level = md.HeadingLevel.H3; | ||
break; | ||
case 4: | ||
level = md.HeadingLevel.H4; | ||
break; | ||
case 5: | ||
level = md.HeadingLevel.H5; | ||
break; | ||
default: | ||
level = md.HeadingLevel.H6; | ||
break; | ||
} | ||
const nodes = block.block.split(" "); | ||
nodes.shift(); | ||
const actual_nodes = parse_nodes(nodes.join(" "), false, context); | ||
return new md.Heading(actual_nodes, level); | ||
return new md.Heading(actual_nodes, Math.min(nodes[0].length, md.HeadingLevel.H6)); | ||
} | ||
case "horizontal_rule": | ||
return md.HORIZONTAL_RULE; | ||
|
@@ -903,7 +884,7 @@ function parse_block(block: BlockGroup, context: ParsingContext): md.BlockElemen | |
level = indent[1].length / 2 >> 0; | ||
} | ||
|
||
for (let i = level; level > 0; level--) { | ||
for (; level > 0; level--) { | ||
if (current_list[level - 1]) { | ||
break; | ||
} | ||
|
Oops, something went wrong.