Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 10 additions & 21 deletions src/writr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,8 @@ import { WritrHooks } from "./types.js";
import { WritrAI } from "./writr-ai.js";

export class Writr extends Hookified {
public engine = unified()
.use(remarkParse)
.use(remarkGfm) // Use GitHub Flavored Markdown
.use(remarkToc) // Add table of contents
.use(remarkEmoji) // Add emoji support
.use(remarkRehype) // Convert markdown to HTML
.use(rehypeSlug) // Add slugs to headings in HTML
.use(remarkMath) // Add math support
.use(rehypeKatex) // Add math support
.use(rehypeHighlight) // Apply syntax highlighting
.use(rehypeStringify); // Stringify HTML
// biome-ignore lint/suspicious/noExplicitAny: expected unified processor
public engine: any;

private readonly _options: WritrOptions = {
renderOptions: {
Expand Down Expand Up @@ -103,20 +94,14 @@ export class Writr extends Hookified {
this._content = arguments1;
} else if (arguments1) {
this._options = this.mergeOptions(this._options, arguments1);
/* v8 ignore next -- @preserve */
if (this._options.renderOptions) {
this.engine = this.createProcessor(this._options.renderOptions);
}
}

if (arguments2) {
this._options = this.mergeOptions(this._options, arguments2);
/* v8 ignore next -- @preserve */
if (this._options.renderOptions) {
this.engine = this.createProcessor(this._options.renderOptions);
}
}

this.engine = this.createProcessor(this._options.renderOptions ?? {});

if (this._options.ai) {
this._ai = new WritrAI(this, this._options.ai);
}
Expand Down Expand Up @@ -651,7 +636,7 @@ export class Writr extends Hookified {
}

if (options.toc) {
processor.use(remarkToc, { heading: "toc|table of contents" });
processor.use(remarkToc);
}

if (options.emoji) {
Expand All @@ -662,6 +647,10 @@ export class Writr extends Hookified {
processor.use(remarkMDX);
}

if (options.math) {
processor.use(remarkMath);
}

// biome-ignore lint/suspicious/noExplicitAny: remarkRehype handler types
const rehypeOptions: Record<string, any> = {};

Expand Down Expand Up @@ -691,7 +680,7 @@ export class Writr extends Hookified {
}

if (options.math) {
processor.use(remarkMath).use(rehypeKatex);
processor.use(rehypeKatex);
}

processor.use(rehypeStringify);
Expand Down
32 changes: 32 additions & 0 deletions test/writr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,38 @@ describe("writr", () => {
expect(result).toContain("NOTE");
expect(result).toContain("This is a note alert with useful information.");
});
it("should render lists inside blockquotes correctly", async () => {
const md =
"> 🚧 At this time Hyphen Deploy supports containerized applications running on:\n>\n> - 🚧 Amazon Elastic Container Service (ECS)\n> - 🚧 Azure Container Apps\n> - 🚧 Google Cloudrun";
const writr = new Writr(md);
const result = await writr.render();
expect(result).toContain("<blockquote>");
expect(result).toContain("<ul>");
expect(result).toContain(
"<li>🚧 Amazon Elastic Container Service (ECS)</li>",
);
expect(result).toContain("<li>🚧 Azure Container Apps</li>");
expect(result).toContain("<li>🚧 Google Cloudrun</li>");
});
it("should render lists inside blockquotes without blank separator line", async () => {
const md = "> Text:\n> - item1\n> - item2\n> - item3";
const writr = new Writr(md);
const result = await writr.render();
expect(result).toContain("<blockquote>");
expect(result).toContain("<ul>");
expect(result).toContain("<li>item1</li>");
expect(result).toContain("<li>item2</li>");
expect(result).toContain("<li>item3</li>");
});
it("should render lists inside blockquotes with renderSync", () => {
const md = "> Text:\n>\n> - item1\n> - item2";
const writr = new Writr(md);
const result = writr.renderSync();
expect(result).toContain("<blockquote>");
expect(result).toContain("<ul>");
expect(result).toContain("<li>item1</li>");
expect(result).toContain("<li>item2</li>");
});
it("should not render GitHub blockquote alerts when gfm is disabled", async () => {
const writr = new Writr(
"> [!NOTE]\n> This is a note alert with useful information.",
Expand Down
Loading