pict-section-content 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +138 -0
- package/docs/README.md +130 -0
- package/docs/_sidebar.md +19 -0
- package/docs/_topbar.md +7 -0
- package/docs/api.md +323 -0
- package/docs/cover.md +15 -0
- package/docs/extending.md +184 -0
- package/docs/link-resolver.md +136 -0
- package/package.json +51 -0
- package/source/Pict-Section-Content.js +7 -0
- package/source/providers/Pict-Provider-Content.js +404 -0
- package/source/views/Pict-View-Content.js +307 -0
- package/test/Pict-Section-Content_tests.js +482 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Steven Velozo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# Pict Section Content
|
|
2
|
+
|
|
3
|
+
A reusable content rendering section for the Pict ecosystem. Parses markdown to HTML with support for fenced code blocks, Mermaid diagrams, KaTeX math equations, GFM tables, and more. Provides a styled content view with post-render hooks for Mermaid and KaTeX integration.
|
|
4
|
+
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Markdown Parsing** -- Headings, paragraphs, lists, blockquotes, horizontal rules, fenced code blocks (with nested fence support), GFM tables, and inline formatting
|
|
12
|
+
- **Mermaid Diagrams** -- Code blocks tagged `mermaid` render as diagrams when the Mermaid library is present
|
|
13
|
+
- **KaTeX Math** -- Inline (`$...$`) and display (`$$...$$`) math equations render when KaTeX is loaded
|
|
14
|
+
- **Link Resolver** -- Pluggable callback for custom link resolution, enabling consumers to map links to application-specific routes
|
|
15
|
+
- **Content View** -- Styled view with CSS for all rendered elements, post-render hooks for Mermaid and KaTeX, and a loading indicator
|
|
16
|
+
- **Extensible** -- Extend the view class to use custom container IDs, override styling, or add post-render behavior
|
|
17
|
+
- **Service Provider Pattern** -- Both the provider and view register with a Pict instance via dependency injection
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install pict-section-content
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
### Parsing Markdown (Provider)
|
|
28
|
+
|
|
29
|
+
```javascript
|
|
30
|
+
const libPict = require('pict');
|
|
31
|
+
const libPictSectionContent = require('pict-section-content');
|
|
32
|
+
const PictContentProvider = libPictSectionContent.PictContentProvider;
|
|
33
|
+
|
|
34
|
+
let tmpPict = new libPict();
|
|
35
|
+
let tmpProvider = tmpPict.addProvider('Content',
|
|
36
|
+
PictContentProvider.default_configuration, PictContentProvider);
|
|
37
|
+
|
|
38
|
+
let tmpHTML = tmpProvider.parseMarkdown('# Hello World\n\nThis is **bold** text.');
|
|
39
|
+
// <h1 id="hello-world">Hello World</h1>
|
|
40
|
+
// <p>This is <strong>bold</strong> text.</p>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Displaying Content (View)
|
|
44
|
+
|
|
45
|
+
```javascript
|
|
46
|
+
const libPictSectionContent = require('pict-section-content');
|
|
47
|
+
|
|
48
|
+
// Register the view with your Pict application
|
|
49
|
+
let tmpView = tmpPict.addView('Content',
|
|
50
|
+
libPictSectionContent.default_configuration, libPictSectionContent);
|
|
51
|
+
|
|
52
|
+
// Render the container, then display parsed HTML
|
|
53
|
+
tmpView.render();
|
|
54
|
+
tmpView.displayContent(tmpHTML);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Custom Link Resolution
|
|
58
|
+
|
|
59
|
+
```javascript
|
|
60
|
+
let tmpResolver = (pHref, pLinkText) =>
|
|
61
|
+
{
|
|
62
|
+
if (pHref.match(/\.md$/))
|
|
63
|
+
{
|
|
64
|
+
return { href: '#/page/' + pHref.replace(/\.md$/, '') };
|
|
65
|
+
}
|
|
66
|
+
return null; // fall back to default behavior
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
let tmpHTML = tmpProvider.parseMarkdown(markdown, tmpResolver);
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Supported Markdown
|
|
73
|
+
|
|
74
|
+
| Feature | Syntax |
|
|
75
|
+
|---------|--------|
|
|
76
|
+
| Headings | `# H1` through `###### H6` |
|
|
77
|
+
| Bold | `**text**` or `__text__` |
|
|
78
|
+
| Italic | `*text*` or `_text_` |
|
|
79
|
+
| Inline code | `` `code` `` |
|
|
80
|
+
| Links | `[text](url)` |
|
|
81
|
+
| Images | `` |
|
|
82
|
+
| Code blocks | ```` ``` ```` with optional language tag |
|
|
83
|
+
| Mermaid | ```` ```mermaid ```` |
|
|
84
|
+
| Tables | GFM pipe syntax |
|
|
85
|
+
| Lists | `- item` or `1. item` |
|
|
86
|
+
| Blockquotes | `> text` |
|
|
87
|
+
| Horizontal rules | `---`, `***`, or `___` |
|
|
88
|
+
| Inline math | `$equation$` |
|
|
89
|
+
| Display math | `$$...$$` |
|
|
90
|
+
|
|
91
|
+
## Module Exports
|
|
92
|
+
|
|
93
|
+
```javascript
|
|
94
|
+
const libPictSectionContent = require('pict-section-content');
|
|
95
|
+
|
|
96
|
+
// Primary export: the content view class
|
|
97
|
+
libPictSectionContent // PictContentView (extends pict-view)
|
|
98
|
+
libPictSectionContent.default_configuration // View configuration with CSS and templates
|
|
99
|
+
|
|
100
|
+
// Named export: the content provider class
|
|
101
|
+
libPictSectionContent.PictContentProvider // PictContentProvider (extends pict-provider)
|
|
102
|
+
libPictSectionContent.PictContentProvider.default_configuration // Provider configuration
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## External Dependencies
|
|
106
|
+
|
|
107
|
+
For full rendering, load these libraries in the browser:
|
|
108
|
+
|
|
109
|
+
- **Mermaid** -- Renders diagram blocks (optional, detected at runtime)
|
|
110
|
+
- **KaTeX** -- Renders math equations (optional, detected at runtime)
|
|
111
|
+
|
|
112
|
+
Content renders without them; diagrams and equations appear as raw text.
|
|
113
|
+
|
|
114
|
+
## Part of the Retold Framework
|
|
115
|
+
|
|
116
|
+
- [pict](https://github.com/stevenvelozo/pict) -- UI framework
|
|
117
|
+
- [pict-view](https://github.com/stevenvelozo/pict-view) -- View base class
|
|
118
|
+
- [pict-provider](https://github.com/stevenvelozo/pict-provider) -- Provider base class
|
|
119
|
+
- [pict-docuserve](https://github.com/stevenvelozo/pict-docuserve) -- Documentation server (uses this module)
|
|
120
|
+
- [fable](https://github.com/stevenvelozo/fable) -- Application services framework
|
|
121
|
+
|
|
122
|
+
## Testing
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
npm test
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
npm run coverage
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
MIT - See [LICENSE](LICENSE) for details.
|
|
135
|
+
|
|
136
|
+
## Author
|
|
137
|
+
|
|
138
|
+
Steven Velozo - [steven@velozo.com](mailto:steven@velozo.com)
|
package/docs/README.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# Pict Section Content
|
|
2
|
+
|
|
3
|
+
A reusable content rendering section for the Pict ecosystem. Provides a markdown-to-HTML parser (the provider) and a styled content display view with post-render hooks for Mermaid diagrams and KaTeX math equations.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install pict-section-content
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### Parsing Markdown
|
|
12
|
+
|
|
13
|
+
The content provider parses markdown into HTML. Create a provider instance via Pict's `addProvider` method:
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
const libPict = require('pict');
|
|
17
|
+
const libPictSectionContent = require('pict-section-content');
|
|
18
|
+
const PictContentProvider = libPictSectionContent.PictContentProvider;
|
|
19
|
+
|
|
20
|
+
let tmpPict = new libPict();
|
|
21
|
+
let tmpProvider = tmpPict.addProvider('Content',
|
|
22
|
+
PictContentProvider.default_configuration, PictContentProvider);
|
|
23
|
+
|
|
24
|
+
let tmpHTML = tmpProvider.parseMarkdown('# Hello World\n\nThis is **bold** text.');
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The parser handles headings, paragraphs, lists, blockquotes, horizontal rules, fenced code blocks (with nested fence support), GFM tables, Mermaid diagram blocks, KaTeX math (inline and display), and all standard inline formatting (bold, italic, code, links, images).
|
|
28
|
+
|
|
29
|
+
### Displaying Content
|
|
30
|
+
|
|
31
|
+
The content view renders parsed HTML into a styled container and triggers post-render hooks for Mermaid and KaTeX:
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
const libPictSectionContent = require('pict-section-content');
|
|
35
|
+
|
|
36
|
+
// Register the view
|
|
37
|
+
let tmpView = tmpPict.addView('Content',
|
|
38
|
+
libPictSectionContent.default_configuration, libPictSectionContent);
|
|
39
|
+
|
|
40
|
+
// Render the container, then display content
|
|
41
|
+
tmpView.render();
|
|
42
|
+
tmpView.displayContent(tmpHTML);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The view provides CSS for all rendered elements and automatically initializes Mermaid diagrams and KaTeX equations after content is assigned.
|
|
46
|
+
|
|
47
|
+
### Custom Link Resolution
|
|
48
|
+
|
|
49
|
+
By default, external links (`https://...`) open in a new tab with `rel="noopener"` and relative links render as-is. To customize link handling, pass a resolver callback:
|
|
50
|
+
|
|
51
|
+
```javascript
|
|
52
|
+
let tmpResolver = (pHref, pLinkText) =>
|
|
53
|
+
{
|
|
54
|
+
// Convert .md links to hash routes
|
|
55
|
+
if (pHref.match(/\.md$/))
|
|
56
|
+
{
|
|
57
|
+
return { href: '#/page/' + pHref.replace(/\.md$/, '') };
|
|
58
|
+
}
|
|
59
|
+
// Return null to use default behavior
|
|
60
|
+
return null;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
let tmpHTML = tmpProvider.parseMarkdown(markdown, tmpResolver);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
See [Link Resolver](link-resolver.md) for the full pattern documentation.
|
|
67
|
+
|
|
68
|
+
## Module Structure
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
pict-section-content/
|
|
72
|
+
source/
|
|
73
|
+
Pict-Section-Content.js # Entry point
|
|
74
|
+
providers/
|
|
75
|
+
Pict-Provider-Content.js # Markdown parser (extends pict-provider)
|
|
76
|
+
views/
|
|
77
|
+
Pict-View-Content.js # Content display (extends pict-view)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The primary export is the view class. The provider is available as a named export:
|
|
81
|
+
|
|
82
|
+
```javascript
|
|
83
|
+
const PictContentView = require('pict-section-content');
|
|
84
|
+
const PictContentProvider = require('pict-section-content').PictContentProvider;
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Supported Markdown
|
|
88
|
+
|
|
89
|
+
### Block Elements
|
|
90
|
+
|
|
91
|
+
| Feature | Syntax | Output |
|
|
92
|
+
|---------|--------|--------|
|
|
93
|
+
| Headings | `# H1` through `###### H6` | `<h1>` through `<h6>` with auto-generated `id` |
|
|
94
|
+
| Paragraphs | Plain text | `<p>` |
|
|
95
|
+
| Code blocks | ```` ``` ```` with optional language | `<pre><code class="language-...">` |
|
|
96
|
+
| Mermaid | ```` ```mermaid ```` | `<pre class="mermaid">` |
|
|
97
|
+
| Unordered lists | `- item` or `* item` | `<ul><li>` |
|
|
98
|
+
| Ordered lists | `1. item` | `<ol><li>` |
|
|
99
|
+
| Blockquotes | `> text` | `<blockquote>` (recursive) |
|
|
100
|
+
| Tables | GFM pipe syntax | `<table>` with `<thead>` and `<tbody>` |
|
|
101
|
+
| Horizontal rules | `---`, `***`, or `___` | `<hr>` |
|
|
102
|
+
| Display math | `$$...$$` | `<div class="pict-content-katex-display">` |
|
|
103
|
+
|
|
104
|
+
### Inline Elements
|
|
105
|
+
|
|
106
|
+
| Feature | Syntax | Output |
|
|
107
|
+
|---------|--------|--------|
|
|
108
|
+
| Bold | `**text**` or `__text__` | `<strong>` |
|
|
109
|
+
| Italic | `*text*` or `_text_` | `<em>` |
|
|
110
|
+
| Inline code | `` `code` `` | `<code>` |
|
|
111
|
+
| Links | `[text](url)` | `<a>` |
|
|
112
|
+
| Images | `` | `<img>` |
|
|
113
|
+
| Inline math | `$equation$` | `<span class="pict-content-katex-inline">` |
|
|
114
|
+
|
|
115
|
+
## External Dependencies
|
|
116
|
+
|
|
117
|
+
For full rendering in the browser, load these libraries:
|
|
118
|
+
|
|
119
|
+
- **Mermaid** -- Renders `<pre class="mermaid">` elements into diagrams
|
|
120
|
+
- **KaTeX** -- Renders `.pict-content-katex-inline` and `.pict-content-katex-display` elements
|
|
121
|
+
|
|
122
|
+
Both are detected at runtime. Without them, content renders normally but diagrams and equations appear as raw text.
|
|
123
|
+
|
|
124
|
+
## Learn More
|
|
125
|
+
|
|
126
|
+
- [API Reference](api.md) -- Complete method and property documentation
|
|
127
|
+
- [Link Resolver](link-resolver.md) -- Custom link resolution pattern
|
|
128
|
+
- [Extending the View](extending.md) -- Using pict-section-content as a base class
|
|
129
|
+
- [Pict View](/pict/pict-view/) -- View base class documentation
|
|
130
|
+
- [Pict Provider](/pict/pict-provider/) -- Provider base class documentation
|
package/docs/_sidebar.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
- Getting Started
|
|
2
|
+
|
|
3
|
+
- [Overview](README.md)
|
|
4
|
+
- [Link Resolver](link-resolver.md)
|
|
5
|
+
- [Extending the View](extending.md)
|
|
6
|
+
|
|
7
|
+
- Reference
|
|
8
|
+
|
|
9
|
+
- [API Reference](api.md)
|
|
10
|
+
|
|
11
|
+
- Retold Ecosystem
|
|
12
|
+
|
|
13
|
+
- [Pict](/pict/pict/)
|
|
14
|
+
- [Pict Application](/pict/pict-application/)
|
|
15
|
+
- [Pict View](/pict/pict-view/)
|
|
16
|
+
- [Pict Provider](/pict/pict-provider/)
|
|
17
|
+
- [Pict Docuserve](/pict/pict-docuserve/)
|
|
18
|
+
- [Fable](/fable/fable/)
|
|
19
|
+
- [Fable Service Base](/fable/fable-serviceproviderbase/)
|
package/docs/_topbar.md
ADDED
package/docs/api.md
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
# API Reference
|
|
2
|
+
|
|
3
|
+
## PictContentProvider
|
|
4
|
+
|
|
5
|
+
Extends `pict-provider`. Service type: `'PictProvider'`.
|
|
6
|
+
|
|
7
|
+
The content provider parses markdown into HTML. It handles block-level elements (headings, code blocks, lists, tables, blockquotes, math blocks) and inline elements (bold, italic, code, links, images, inline math).
|
|
8
|
+
|
|
9
|
+
### Constructor
|
|
10
|
+
|
|
11
|
+
```javascript
|
|
12
|
+
new PictContentProvider(pFable, pOptions, pServiceHash)
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
| Parameter | Type | Description |
|
|
16
|
+
|-----------|------|-------------|
|
|
17
|
+
| `pFable` | object | A Fable or Pict instance |
|
|
18
|
+
| `pOptions` | object | Configuration options (merged with defaults) |
|
|
19
|
+
| `pServiceHash` | string | Service identifier for the provider registry |
|
|
20
|
+
|
|
21
|
+
### Default Configuration
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
{
|
|
25
|
+
ProviderIdentifier: "Pict-Content",
|
|
26
|
+
AutoInitialize: true,
|
|
27
|
+
AutoInitializeOrdinal: 0
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
### parseMarkdown(pMarkdown, pLinkResolver)
|
|
34
|
+
|
|
35
|
+
Parse a markdown string into HTML. Processes block-level elements line by line, delegating inline formatting to `parseInline`. The optional `pLinkResolver` callback is threaded through to inline parsing and into recursive calls (for blockquotes).
|
|
36
|
+
|
|
37
|
+
| Parameter | Type | Description |
|
|
38
|
+
|-----------|------|-------------|
|
|
39
|
+
| `pMarkdown` | string | The raw markdown text |
|
|
40
|
+
| `pLinkResolver` | function | Optional link resolver callback (see [Link Resolver](link-resolver.md)) |
|
|
41
|
+
|
|
42
|
+
**Returns:** `string` -- The parsed HTML
|
|
43
|
+
|
|
44
|
+
**Block elements handled:**
|
|
45
|
+
|
|
46
|
+
| Element | Detection | Output |
|
|
47
|
+
|---------|-----------|--------|
|
|
48
|
+
| Headings | `# ` through `###### ` | `<h1 id="...">` through `<h6 id="...">` |
|
|
49
|
+
| Code blocks | ```` ``` ```` with optional language | `<pre><code class="language-...">` |
|
|
50
|
+
| Mermaid blocks | ```` ```mermaid ```` | `<pre class="mermaid">` |
|
|
51
|
+
| Unordered lists | `- `, `* `, `+ ` | `<ul><li>` |
|
|
52
|
+
| Ordered lists | `1. ` | `<ol><li>` |
|
|
53
|
+
| Blockquotes | `> ` | `<blockquote>` (recursive markdown parsing) |
|
|
54
|
+
| Tables | `| ... |` with separator row | `<table>` with `<thead>` and `<tbody>` |
|
|
55
|
+
| Horizontal rules | `---`, `***`, `___` | `<hr>` |
|
|
56
|
+
| Display math | `$$` delimiters | `<div class="pict-content-katex-display">` |
|
|
57
|
+
| Paragraphs | Any other non-empty line | `<p>` |
|
|
58
|
+
|
|
59
|
+
**Code block nesting:** The parser tracks fence length (number of backticks). A closing fence must have at least as many backticks as the opening fence. This allows ```` ```` ```` to contain ```` ``` ```` blocks as content.
|
|
60
|
+
|
|
61
|
+
**Example:**
|
|
62
|
+
|
|
63
|
+
```javascript
|
|
64
|
+
let tmpProvider = tmpPict.addProvider('Content',
|
|
65
|
+
PictContentProvider.default_configuration, PictContentProvider);
|
|
66
|
+
|
|
67
|
+
let tmpHTML = tmpProvider.parseMarkdown(
|
|
68
|
+
'# Heading\n\n'
|
|
69
|
+
+ 'A paragraph with **bold** text.\n\n'
|
|
70
|
+
+ '- Item one\n'
|
|
71
|
+
+ '- Item two\n\n'
|
|
72
|
+
+ '```javascript\nlet x = 1;\n```'
|
|
73
|
+
);
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
### parseInline(pText, pLinkResolver)
|
|
79
|
+
|
|
80
|
+
Parse inline markdown elements within a single line of text. Called by `parseMarkdown` for each line that contains inline content (headings, paragraphs, list items, table cells).
|
|
81
|
+
|
|
82
|
+
Processing order:
|
|
83
|
+
1. Inline code (backticks)
|
|
84
|
+
2. Inline LaTeX (`$...$`)
|
|
85
|
+
3. Images (``)
|
|
86
|
+
4. Links (`[text](url)`) -- with optional resolver
|
|
87
|
+
5. Bold (`**text**` and `__text__`)
|
|
88
|
+
6. Italic (`*text*` and `_text_`)
|
|
89
|
+
|
|
90
|
+
| Parameter | Type | Description |
|
|
91
|
+
|-----------|------|-------------|
|
|
92
|
+
| `pText` | string | The text to parse |
|
|
93
|
+
| `pLinkResolver` | function | Optional link resolver callback |
|
|
94
|
+
|
|
95
|
+
**Returns:** `string` -- HTML with inline elements
|
|
96
|
+
|
|
97
|
+
**Link behavior without resolver:**
|
|
98
|
+
- External links (`https://...` or `http://...`) get `target="_blank" rel="noopener"`
|
|
99
|
+
- All other links render as plain `<a href="...">` tags
|
|
100
|
+
|
|
101
|
+
**Example:**
|
|
102
|
+
|
|
103
|
+
```javascript
|
|
104
|
+
tmpProvider.parseInline('**bold** and *italic* and `code`');
|
|
105
|
+
// '<strong>bold</strong> and <em>italic</em> and <code>code</code>'
|
|
106
|
+
|
|
107
|
+
tmpProvider.parseInline('[GitHub](https://github.com)');
|
|
108
|
+
// '<a href="https://github.com" target="_blank" rel="noopener">GitHub</a>'
|
|
109
|
+
|
|
110
|
+
tmpProvider.parseInline('[Guide](guide.md)');
|
|
111
|
+
// '<a href="guide.md">Guide</a>'
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
### escapeHTML(pText)
|
|
117
|
+
|
|
118
|
+
Escape HTML special characters to prevent XSS and ensure safe rendering inside HTML contexts. Used internally for code block content.
|
|
119
|
+
|
|
120
|
+
| Parameter | Type | Description |
|
|
121
|
+
|-----------|------|-------------|
|
|
122
|
+
| `pText` | string | The text to escape |
|
|
123
|
+
|
|
124
|
+
**Returns:** `string` -- The escaped text
|
|
125
|
+
|
|
126
|
+
**Characters escaped:**
|
|
127
|
+
|
|
128
|
+
| Character | Replacement |
|
|
129
|
+
|-----------|-------------|
|
|
130
|
+
| `&` | `&` |
|
|
131
|
+
| `<` | `<` |
|
|
132
|
+
| `>` | `>` |
|
|
133
|
+
| `"` | `"` |
|
|
134
|
+
| `'` | `'` |
|
|
135
|
+
|
|
136
|
+
**Example:**
|
|
137
|
+
|
|
138
|
+
```javascript
|
|
139
|
+
tmpProvider.escapeHTML('<script>alert("xss")</script>');
|
|
140
|
+
// '<script>alert("xss")</script>'
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## PictContentView
|
|
146
|
+
|
|
147
|
+
Extends `pict-view`. Provides a styled content container with post-render hooks for Mermaid diagrams and KaTeX math equations.
|
|
148
|
+
|
|
149
|
+
### Constructor
|
|
150
|
+
|
|
151
|
+
```javascript
|
|
152
|
+
new PictContentView(pFable, pOptions, pServiceHash)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
| Parameter | Type | Description |
|
|
156
|
+
|-----------|------|-------------|
|
|
157
|
+
| `pFable` | object | A Fable or Pict instance |
|
|
158
|
+
| `pOptions` | object | Configuration options (merged with defaults) |
|
|
159
|
+
| `pServiceHash` | string | Service identifier for the view registry |
|
|
160
|
+
|
|
161
|
+
### Default Configuration
|
|
162
|
+
|
|
163
|
+
```javascript
|
|
164
|
+
{
|
|
165
|
+
ViewIdentifier: "Pict-Content",
|
|
166
|
+
DefaultRenderable: "Pict-Content-Display",
|
|
167
|
+
DefaultDestinationAddress: "#Pict-Content-Container",
|
|
168
|
+
AutoRender: false,
|
|
169
|
+
|
|
170
|
+
CSS: /* content styles */,
|
|
171
|
+
|
|
172
|
+
Templates:
|
|
173
|
+
[
|
|
174
|
+
{
|
|
175
|
+
Hash: "Pict-Content-Template",
|
|
176
|
+
Template: '<div class="pict-content" id="Pict-Content-Body">...</div>'
|
|
177
|
+
}
|
|
178
|
+
],
|
|
179
|
+
|
|
180
|
+
Renderables:
|
|
181
|
+
[
|
|
182
|
+
{
|
|
183
|
+
RenderableHash: "Pict-Content-Display",
|
|
184
|
+
TemplateHash: "Pict-Content-Template",
|
|
185
|
+
DestinationAddress: "#Pict-Content-Container",
|
|
186
|
+
RenderMethod: "replace"
|
|
187
|
+
}
|
|
188
|
+
]
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
The view's `AutoRender` is `false` by default. Call `render()` explicitly to insert the content container into the DOM.
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
### displayContent(pHTMLContent, pContainerID)
|
|
197
|
+
|
|
198
|
+
Assign HTML content to the container element, scroll to the top, and trigger post-render hooks for Mermaid and KaTeX.
|
|
199
|
+
|
|
200
|
+
| Parameter | Type | Default | Description |
|
|
201
|
+
|-----------|------|---------|-------------|
|
|
202
|
+
| `pHTMLContent` | string | | The HTML to display |
|
|
203
|
+
| `pContainerID` | string | `'Pict-Content-Body'` | The container element ID |
|
|
204
|
+
|
|
205
|
+
**Sequence:**
|
|
206
|
+
1. Assigns content via `pict.ContentAssignment.assignContent`
|
|
207
|
+
2. Scrolls the container's parent to the top
|
|
208
|
+
3. Calls `renderMermaidDiagrams(pContainerID)`
|
|
209
|
+
4. Calls `renderKaTeXEquations(pContainerID)`
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
### renderMermaidDiagrams(pContainerID)
|
|
214
|
+
|
|
215
|
+
Find all `<pre class="mermaid">` elements in the container and render them using the Mermaid library. If `mermaid` is not defined globally, this method returns immediately.
|
|
216
|
+
|
|
217
|
+
| Parameter | Type | Default | Description |
|
|
218
|
+
|-----------|------|---------|-------------|
|
|
219
|
+
| `pContainerID` | string | `'Pict-Content-Body'` | The container element ID |
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
### renderKaTeXEquations(pContainerID)
|
|
224
|
+
|
|
225
|
+
Find all `.pict-content-katex-inline` and `.pict-content-katex-display` elements in the container and render them using the KaTeX library. If `katex` is not defined globally, this method returns immediately.
|
|
226
|
+
|
|
227
|
+
| Parameter | Type | Default | Description |
|
|
228
|
+
|-----------|------|---------|-------------|
|
|
229
|
+
| `pContainerID` | string | `'Pict-Content-Body'` | The container element ID |
|
|
230
|
+
|
|
231
|
+
**Element types:**
|
|
232
|
+
- `.pict-content-katex-inline` -- Rendered with `displayMode: false`
|
|
233
|
+
- `.pict-content-katex-display` -- Rendered with `displayMode: true`
|
|
234
|
+
|
|
235
|
+
Both use `throwOnError: false` to prevent rendering failures from propagating.
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
### showLoading(pMessage, pContainerID)
|
|
240
|
+
|
|
241
|
+
Display a loading indicator inside the content container.
|
|
242
|
+
|
|
243
|
+
| Parameter | Type | Default | Description |
|
|
244
|
+
|-----------|------|---------|-------------|
|
|
245
|
+
| `pMessage` | string | `'Loading content...'` | The loading message |
|
|
246
|
+
| `pContainerID` | string | `'Pict-Content-Body'` | The container element ID |
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
## CSS Classes
|
|
251
|
+
|
|
252
|
+
The view registers CSS styles for the `.pict-content` container and all rendered elements within it.
|
|
253
|
+
|
|
254
|
+
### Layout
|
|
255
|
+
|
|
256
|
+
| Class | Description |
|
|
257
|
+
|-------|-------------|
|
|
258
|
+
| `.pict-content` | Main content wrapper. Max width 900px, centered, padded. |
|
|
259
|
+
| `.pict-content-loading` | Loading indicator. Centered, minimum height 200px. |
|
|
260
|
+
|
|
261
|
+
### Typography
|
|
262
|
+
|
|
263
|
+
| Selector | Description |
|
|
264
|
+
|----------|-------------|
|
|
265
|
+
| `.pict-content h1` | Primary heading. Bottom border, no top margin. |
|
|
266
|
+
| `.pict-content h2` | Section heading. Light bottom border. |
|
|
267
|
+
| `.pict-content h3` | Subsection heading. |
|
|
268
|
+
| `.pict-content h4, h5, h6` | Minor headings. |
|
|
269
|
+
| `.pict-content p` | Paragraph. Line height 1.7. |
|
|
270
|
+
| `.pict-content a` | Links. Teal color, underline on hover. |
|
|
271
|
+
|
|
272
|
+
### Code
|
|
273
|
+
|
|
274
|
+
| Selector | Description |
|
|
275
|
+
|----------|-------------|
|
|
276
|
+
| `.pict-content pre` | Code block. Dark background, rounded corners. |
|
|
277
|
+
| `.pict-content code` | Inline code. Light background, warm accent color. |
|
|
278
|
+
| `.pict-content pre code` | Code inside pre block. Inherits pre styling. |
|
|
279
|
+
|
|
280
|
+
### Lists and Quotes
|
|
281
|
+
|
|
282
|
+
| Selector | Description |
|
|
283
|
+
|----------|-------------|
|
|
284
|
+
| `.pict-content ul, ol` | List containers. Left padding, line height 1.8. |
|
|
285
|
+
| `.pict-content li` | List items. |
|
|
286
|
+
| `.pict-content blockquote` | Block quote. Left border, light background. |
|
|
287
|
+
|
|
288
|
+
### Tables
|
|
289
|
+
|
|
290
|
+
| Selector | Description |
|
|
291
|
+
|----------|-------------|
|
|
292
|
+
| `.pict-content table` | Full width, collapsed borders. |
|
|
293
|
+
| `.pict-content table th` | Header cells. Warm background, bold. |
|
|
294
|
+
| `.pict-content table td` | Body cells. |
|
|
295
|
+
| `.pict-content table tr:nth-child(even)` | Alternating row background. |
|
|
296
|
+
|
|
297
|
+
### Special Elements
|
|
298
|
+
|
|
299
|
+
| Selector | Description |
|
|
300
|
+
|----------|-------------|
|
|
301
|
+
| `.pict-content img` | Images. Max width 100%, auto height. |
|
|
302
|
+
| `.pict-content hr` | Horizontal rule. Light border. |
|
|
303
|
+
| `.pict-content pre.mermaid` | Mermaid diagram container. White background, centered. |
|
|
304
|
+
| `.pict-content .pict-content-katex-display` | Display math. Centered, padded. |
|
|
305
|
+
| `.pict-content .pict-content-katex-inline` | Inline math. |
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
309
|
+
## Inherited from pict-view
|
|
310
|
+
|
|
311
|
+
PictContentView inherits the full view interface. Key inherited members:
|
|
312
|
+
|
|
313
|
+
| Member | Description |
|
|
314
|
+
|--------|-------------|
|
|
315
|
+
| `render()` | Render the view's template to the DOM |
|
|
316
|
+
| `pict` | The Pict instance |
|
|
317
|
+
| `AppData` | Shared application state |
|
|
318
|
+
| `log` | Logger instance |
|
|
319
|
+
| `options` | Merged configuration |
|
|
320
|
+
| `UUID` | Unique service identifier |
|
|
321
|
+
| `Hash` | Service registry hash |
|
|
322
|
+
|
|
323
|
+
See [Pict View](/pict/pict-view/) for the complete view API.
|
package/docs/cover.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Pict Section Content
|
|
2
|
+
|
|
3
|
+
> Markdown parsing and content rendering for the Pict ecosystem
|
|
4
|
+
|
|
5
|
+
Parse markdown to HTML with support for code blocks, Mermaid diagrams, KaTeX math, GFM tables, and customizable link resolution. Display content with a styled view that handles post-render initialization of diagrams and equations.
|
|
6
|
+
|
|
7
|
+
- **Markdown Parser** -- Full block and inline markdown support with HTML escaping
|
|
8
|
+
- **Mermaid & KaTeX** -- Post-render hooks for diagram and math rendering
|
|
9
|
+
- **Link Resolver** -- Pluggable callback for application-specific link handling
|
|
10
|
+
- **Extensible View** -- Inherit and customize container IDs, styling, and behavior
|
|
11
|
+
|
|
12
|
+
[Quick Start](README.md)
|
|
13
|
+
[API Reference](api.md)
|
|
14
|
+
[Link Resolver](link-resolver.md)
|
|
15
|
+
[GitHub](https://github.com/stevenvelozo/pict-section-content)
|