Skip to content

Commit a053b00

Browse files
committed
updated docs for 1.1.0 release
1 parent d4e7883 commit a053b00

19 files changed

+244
-119
lines changed

README.md

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Quikdown is a small, secure markdown parser with bidirectional conversion. Zero
99

1010
For small and fast projects quikdown includes built-in inline styles for a "batteries included" rendering experience, but these can be overridden with themed css (see light and dark examples).
1111

12-
- **quikdown.js** (9.1KB) - Markdown to HTML Parser
12+
- **quikdown.js** (9.0KB) - Markdown to HTML Parser
1313
- **quikdown_bd.js** (13.8KB) - Bidirectional (HTML ↔ Markdown) Parser
1414
- **quikdown_edit.js** (37.8KB) - Drop-in editor component (HTML ↔ Markdown) with md/split/html views
1515

@@ -21,7 +21,7 @@ For small and fast projects quikdown includes built-in inline styles for a "batt
2121

2222
- 📦 **Zero dependencies** - No external libraries required
2323
- 🌐 **Universal** - Works in browsers and Node.js
24-
- 🚀 **Lightweight** - 9.1KB (core), 13.8KB (bidirectional), 37.8KB (editor)
24+
- 🚀 **Lightweight** - 9.0KB (core), 13.8KB (bidirectional), 37.8KB (editor)
2525
- 🔒 **Secure by default** - Built-in XSS protection with URL sanitization
2626
- 🎨 **Flexible styling** - Inline styles or CSS classes with theme support
2727
- 🔌 **Plugin system** - Extensible fence block handlers
@@ -108,7 +108,9 @@ quikdown supports built-in styles for a "batteries included" experience or you c
108108
const html = quikdown(markdown, {
109109
lazy_linefeeds: true, // Single newlines become <br>
110110
inline_styles: false, // Use class based CSS instead of inline styles
111-
fence_plugin: myHandler // Custom code block processor
111+
fence_plugin: { // Custom code block processor (v1.1.0+ API)
112+
render: myHandler // Function to render fence blocks
113+
}
112114
});
113115
```
114116

@@ -135,18 +137,19 @@ Quikdown provides a callback for all fenced text such as code blocks, math, svg
135137
Handle code blocks with custom languages:
136138

137139
```javascript
138-
function fencePlugin(code, language) {
139-
if (language === 'mermaid') {
140-
// Process with mermaid library and return rendered diagram
141-
const id = 'mermaid-' + Math.random().toString(36).substr(2, 9);
142-
setTimeout(() => mermaid.render(id + '-svg', code).then(result => {
143-
document.getElementById(id).innerHTML = result.svg;
144-
}), 0);
145-
return `<div id="${id}" class="mermaid">Loading diagram...</div>`;
140+
const fencePlugin = {
141+
render: (code, language) => {
142+
if (language === 'mermaid') {
143+
// Process with mermaid library and return rendered diagram
144+
const id = 'mermaid-' + Math.random().toString(36).substr(2, 9);
145+
setTimeout(() => mermaid.render(id + '-svg', code).then(result => {
146+
document.getElementById(id).innerHTML = result.svg;
147+
}), 0);
148+
return `<div id="${id}" class="mermaid">Loading diagram...</div>`;
149+
}
150+
// Return undefined for default handling
146151
}
147-
return `<pre>${code}</pre>`;
148-
// Return undefined for default handling
149-
}
152+
};
150153

151154
const html = quikdown(markdown, { fence_plugin: fencePlugin });
152155
```
@@ -156,18 +159,21 @@ const html = quikdown(markdown, { fence_plugin: fencePlugin });
156159

157160
quikdown includes TypeScript definitions for better IDE support and type safety:
158161

159-
``` javascript
160-
import quikdown, { QuikdownOptions } from 'quikdown';
162+
```typescript
163+
import quikdown, { QuikdownOptions, FencePlugin } from 'quikdown';
164+
165+
const fencePlugin: FencePlugin = {
166+
render: (content: string, language: string) => {
167+
return `<pre class="hljs ${language}">${content}</pre>`;
168+
}
169+
};
161170

162171
const options: QuikdownOptions = {
163-
inline_styles: true,
164-
fence_plugin: (content: string, language: string) => {
165-
return `<pre class="hljs ${language}">${content}</pre>`;
166-
}
172+
inline_styles: true,
173+
fence_plugin: fencePlugin
167174
};
168175

169176
const html: string = quikdown(markdown, options);
170-
171177
```
172178

173179
## Supported Markdown

dist/quikdown_bd.d.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@ declare module 'quikdown/bd' {
1010
export interface QuikdownBdOptions {
1111
/**
1212
* Custom renderer for fenced code blocks.
13-
* Return undefined to use default rendering.
14-
* @param content - The code block content (unescaped)
15-
* @param language - The language identifier (or empty string)
16-
* @returns HTML string or undefined for default rendering
13+
* Uses the FencePlugin interface from quikdown module.
1714
*/
18-
fence_plugin?: (content: string, language: string) => string | undefined;
15+
fence_plugin?: import('./quikdown').FencePlugin;
1916

2017
/**
2118
* If true, uses inline styles instead of CSS classes.
@@ -107,7 +104,7 @@ declare namespace quikdown_bd {
107104
}
108105

109106
export interface QuikdownBdOptions {
110-
fence_plugin?: (content: string, language: string) => string | undefined;
107+
fence_plugin?: import('./quikdown').FencePlugin;
111108
inline_styles?: boolean;
112109
allow_unsafe_urls?: boolean;
113110
bidirectional?: boolean;

docs/README.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,11 @@ <h2>🔒 Security First</h2>
115115

116116
// Trusted HTML requires explicit plugin
117117
const html = quikdown(markdown, {
118-
fence_plugin: (content, lang) =&gt; {
119-
if (lang === &#39;trusted-html&#39; &amp;&amp; isAdmin()) {
120-
return content; // Only for trusted sources
118+
fence_plugin: {
119+
render: (content, lang) =&gt; {
120+
if (lang === &#39;trusted-html&#39; &amp;&amp; isAdmin()) {
121+
return content; // Only for trusted sources
122+
}
121123
}
122124
}
123125
});

docs/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ const html = quikdown(userInput);
5555

5656
// Trusted HTML requires explicit plugin
5757
const html = quikdown(markdown, {
58-
fence_plugin: (content, lang) => {
59-
if (lang === 'trusted-html' && isAdmin()) {
60-
return content; // Only for trusted sources
58+
fence_plugin: {
59+
render: (content, lang) => {
60+
if (lang === 'trusted-html' && isAdmin()) {
61+
return content; // Only for trusted sources
62+
}
6163
}
6264
}
6365
});

docs/api-reference.html

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,9 +868,21 @@ <h3>Bidirectional Module</h3>
868868
<h2>TypeScript</h2>
869869
<p>TypeScript definitions are included for both modules:</p>
870870
<pre><code class="language-typescript">declare module &#39;quikdown&#39; {
871+
interface FencePlugin {
872+
render: (content: string, language: string) =&gt; string | undefined;
873+
reverse?: (element: HTMLElement) =&gt; {
874+
fence: string;
875+
lang: string;
876+
content: string;
877+
} | null;
878+
}
879+
871880
interface QuikdownOptions {
872881
inline_styles?: boolean;
873-
fence_plugin?: (content: string, language: string) =&gt; string | undefined;
882+
fence_plugin?: FencePlugin;
883+
bidirectional?: boolean;
884+
lazy_linefeeds?: boolean;
885+
allow_unsafe_urls?: boolean;
874886
}
875887

876888
interface QuikdownFunction {

docs/api-reference.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,9 +586,21 @@ TypeScript definitions are included for both modules:
586586

587587
```typescript
588588
declare module 'quikdown' {
589+
interface FencePlugin {
590+
render: (content: string, language: string) => string | undefined;
591+
reverse?: (element: HTMLElement) => {
592+
fence: string;
593+
lang: string;
594+
content: string;
595+
} | null;
596+
}
597+
589598
interface QuikdownOptions {
590599
inline_styles?: boolean;
591-
fence_plugin?: (content: string, language: string) => string | undefined;
600+
fence_plugin?: FencePlugin;
601+
bidirectional?: boolean;
602+
lazy_linefeeds?: boolean;
603+
allow_unsafe_urls?: boolean;
592604
}
593605

594606
interface QuikdownFunction {

docs/framework-integration.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -628,9 +628,11 @@ <h2>TypeScript Support</h2>
628628

629629
const options: QuikdownOptions = {
630630
inline_styles: true,
631-
fence_plugin: (code: string, lang: string) =&gt; {
632-
// Custom plugin logic
633-
return `&lt;pre class=&quot;${lang}&quot;&gt;${code}&lt;/pre&gt;`;
631+
fence_plugin: {
632+
render: (code: string, lang: string) =&gt; {
633+
// Custom plugin logic
634+
return `&lt;pre class=&quot;${lang}&quot;&gt;${code}&lt;/pre&gt;`;
635+
}
634636
}
635637
};
636638

docs/framework-integration.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,9 +635,11 @@ import quikdown_bd from 'quikdown/bd';
635635

636636
const options: QuikdownOptions = {
637637
inline_styles: true,
638-
fence_plugin: (code: string, lang: string) => {
639-
// Custom plugin logic
640-
return `<pre class="${lang}">${code}</pre>`;
638+
fence_plugin: {
639+
render: (code: string, lang: string) => {
640+
// Custom plugin logic
641+
return `<pre class="${lang}">${code}</pre>`;
642+
}
641643
}
642644
};
643645

docs/quikdown-bidirectional.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ <h3>quikdown_bd(markdown, options)</h3>
146146
<ul>
147147
<li><code>markdown</code> (string): The Markdown source text</li>
148148
<li><code>options</code> (object): Optional configuration<ul>
149-
<li><code>fence_plugin</code> (function): Custom renderer for fenced code blocks</li>
149+
<li><code>fence_plugin</code> (FencePlugin): Custom renderer for fenced code blocks (object with <code>render</code> function)</li>
150150
<li><code>inline_styles</code> (boolean): Use inline styles instead of CSS classes</li>
151151
<li><code>allow_unsafe_urls</code> (boolean): Allow potentially unsafe URLs</li>
152152
<li><code>bidirectional</code> (boolean): Always <code>true</code> for quikdown_bd (automatically set)</li>

docs/quikdown-bidirectional.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Convert Markdown to HTML with bidirectional support.
117117
**Parameters:**
118118
- `markdown` (string): The Markdown source text
119119
- `options` (object): Optional configuration
120-
- `fence_plugin` (function): Custom renderer for fenced code blocks
120+
- `fence_plugin` (FencePlugin): Custom renderer for fenced code blocks (object with `render` function)
121121
- `inline_styles` (boolean): Use inline styles instead of CSS classes
122122
- `allow_unsafe_urls` (boolean): Allow potentially unsafe URLs
123123
- `bidirectional` (boolean): Always `true` for quikdown_bd (automatically set)

0 commit comments

Comments
 (0)