@entropicwarrior/sdoc 0.1.18 → 0.2.1
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/README.md +28 -10
- package/docs/reference/sdoc-authoring.sdoc +126 -7
- package/lexica/specification.sdoc +197 -29
- package/package.json +3 -3
- package/src/notion-renderer.js +3 -0
- package/src/sdoc.js +376 -132
- package/src/slide-renderer.js +21 -6
- package/tools/sdoc2html +32 -0
package/src/slide-renderer.js
CHANGED
|
@@ -130,15 +130,26 @@ function renderTable(table) {
|
|
|
130
130
|
.join("\n");
|
|
131
131
|
const tbody = bodyRows ? `<tbody>\n${bodyRows}\n</tbody>` : "";
|
|
132
132
|
|
|
133
|
-
|
|
133
|
+
const styleParts = [];
|
|
134
|
+
if (opts.width) {
|
|
135
|
+
styleParts.push(`width:${opts.width}`);
|
|
136
|
+
if (opts.width !== "auto") styleParts.push("table-layout:fixed");
|
|
137
|
+
}
|
|
138
|
+
if (opts.align === "center") styleParts.push("margin-left:auto", "margin-right:auto");
|
|
139
|
+
else if (opts.align === "right") styleParts.push("margin-left:auto", "margin-right:0");
|
|
140
|
+
const styleAttr = styleParts.length ? ` style="${styleParts.join(";")}"` : "";
|
|
141
|
+
|
|
142
|
+
return `<table${classAttr}${styleAttr}>${thead}${thead ? "\n" : ""}${tbody}</table>`;
|
|
134
143
|
}
|
|
135
144
|
|
|
136
145
|
function renderNestedScope(scope) {
|
|
146
|
+
if (scope.scopeType === "comment") return "";
|
|
137
147
|
const heading = scope.hasHeading !== false && scope.title
|
|
138
148
|
? `<h3>${renderInline(scope.title)}</h3>`
|
|
139
149
|
: "";
|
|
150
|
+
const typeAttr = scope.scopeType ? ` data-scope-type="${escapeAttr(scope.scopeType)}"` : "";
|
|
140
151
|
const children = scope.children.map((child) => renderNode(child)).join("\n");
|
|
141
|
-
return `<section>${heading}\n${children}</section>`;
|
|
152
|
+
return `<section${typeAttr}>${heading}\n${children}</section>`;
|
|
142
153
|
}
|
|
143
154
|
|
|
144
155
|
function renderChildren(nodes) {
|
|
@@ -179,6 +190,10 @@ function extractNotes(children) {
|
|
|
179
190
|
const notes = [];
|
|
180
191
|
const rest = [];
|
|
181
192
|
for (const child of children) {
|
|
193
|
+
if (child.type === "scope" && child.scopeType === "comment") {
|
|
194
|
+
// :comment scopes are excluded from both notes and content
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
182
197
|
if (child.type === "scope" && child.id && child.id.toLowerCase() === "notes") {
|
|
183
198
|
notes.push(child);
|
|
184
199
|
} else {
|
|
@@ -208,8 +223,8 @@ function renderSlide(scope, slideIndex, overlayHtml) {
|
|
|
208
223
|
let bodyHtml;
|
|
209
224
|
if (config.layout === "two-column") {
|
|
210
225
|
// In two-column layout, child scopes become columns
|
|
211
|
-
const columns = contentNodes.filter((n) => n.type === "scope");
|
|
212
|
-
const nonColumns = contentNodes.filter((n) => n.type !== "scope");
|
|
226
|
+
const columns = contentNodes.filter((n) => n.type === "scope" && n.scopeType !== "comment");
|
|
227
|
+
const nonColumns = contentNodes.filter((n) => n.type !== "scope" || n.scopeType === "comment");
|
|
213
228
|
const preamble = nonColumns.length ? renderChildren(nonColumns) : "";
|
|
214
229
|
const columnsHtml = columns
|
|
215
230
|
.map((col) => {
|
|
@@ -256,8 +271,8 @@ function renderSlides(nodes, options = {}) {
|
|
|
256
271
|
slideScopes = nodes;
|
|
257
272
|
}
|
|
258
273
|
|
|
259
|
-
// Filter to scope nodes only (skip stray paragraphs
|
|
260
|
-
const slides = slideScopes.filter((n) => n.type === "scope");
|
|
274
|
+
// Filter to scope nodes only (skip stray paragraphs and :comment scopes)
|
|
275
|
+
const slides = slideScopes.filter((n) => n.type === "scope" && n.scopeType !== "comment");
|
|
261
276
|
|
|
262
277
|
// Build per-slide footer: < CONFIDENTIAL ---gap--- Company >
|
|
263
278
|
const footerParts = [];
|
package/tools/sdoc2html
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// SDOC → HTML fragment translator
|
|
3
|
+
//
|
|
4
|
+
// Usage:
|
|
5
|
+
// node tools/sdoc2html input.sdoc # read from file
|
|
6
|
+
// cat input.sdoc | node tools/sdoc2html # read from stdin
|
|
7
|
+
//
|
|
8
|
+
// Writes an HTML fragment to stdout (no <!DOCTYPE>, no <html>/<body> wrapper).
|
|
9
|
+
// Designed for integration with github/markup as a translator script.
|
|
10
|
+
|
|
11
|
+
const fs = require("fs");
|
|
12
|
+
const { renderHtmlBody } = require("../src/sdoc");
|
|
13
|
+
|
|
14
|
+
function main() {
|
|
15
|
+
let input;
|
|
16
|
+
const filename = process.argv[2];
|
|
17
|
+
|
|
18
|
+
if (filename) {
|
|
19
|
+
try {
|
|
20
|
+
input = fs.readFileSync(filename, "utf8");
|
|
21
|
+
} catch (err) {
|
|
22
|
+
process.stderr.write(`sdoc2html: ${err.message}\n`);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
} else {
|
|
26
|
+
input = fs.readFileSync(0, "utf8");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
process.stdout.write(renderHtmlBody(input) + "\n");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
main();
|