@tblaisot/prez-as-adoc 0.0.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.
Files changed (41) hide show
  1. package/.github/workflows/release.yml +18 -0
  2. package/README.adoc +30 -0
  3. package/asciidoctor/extensions/slides_treeprocessor.js +96 -0
  4. package/asciidoctor/extensions/speaker_notes_treeprocessor.js +40 -0
  5. package/asciidoctor/templates/admonition.js +10 -0
  6. package/asciidoctor/templates/document.js +86 -0
  7. package/asciidoctor/templates/package.json +3 -0
  8. package/asciidoctor/templates/preamble.js +11 -0
  9. package/asciidoctor/templates/section.js +29 -0
  10. package/asciidoctor/templates/slide.js +54 -0
  11. package/asciidoctor/templates/speaker_note.js +12 -0
  12. package/asciidoctor/templates/title.js +24 -0
  13. package/bespoke-plugins/bespoke-classes.js +44 -0
  14. package/bespoke-plugins/bespoke-debug.js +30 -0
  15. package/bespoke-plugins/bespoke-editor.js +96 -0
  16. package/bespoke-plugins/bespoke-hash.js +89 -0
  17. package/bespoke-plugins/bespoke-nav.js +46 -0
  18. package/bespoke-plugins/bespoke-overview.js +21 -0
  19. package/bespoke-plugins/bespoke-progress.js +18 -0
  20. package/bespoke-plugins/bespoke-scale.js +45 -0
  21. package/bespoke-plugins/bespoke-speaker.js +112 -0
  22. package/bespoke-plugins/bespoke-view-mode.js +51 -0
  23. package/bin/prez-as-adoc.js +52 -0
  24. package/package.json +30 -0
  25. package/statics/assets/bespoke-speaker.css +193 -0
  26. package/statics/assets/bespoke-speaker.html +45 -0
  27. package/statics/assets/bespoke-speaker.js +100 -0
  28. package/statics/styles/blocks/progress.css +56 -0
  29. package/statics/styles/debug.css +9 -0
  30. package/statics/styles/deck/deck-full.css +19 -0
  31. package/statics/styles/deck/deck-grid.css +13 -0
  32. package/statics/styles/deck/deck-list.css +58 -0
  33. package/statics/styles/deck/deck-pointless.css +5 -0
  34. package/statics/styles/deck/deck-print.css +11 -0
  35. package/statics/styles/deck/deck.css +31 -0
  36. package/statics/styles/main.css +6 -0
  37. package/statics/styles/normalize.css +226 -0
  38. package/statics/styles/slide/slide-full.css +16 -0
  39. package/statics/styles/slide/slide-list.css +31 -0
  40. package/statics/styles/slide/slide.css +28 -0
  41. package/vitejs/plugins/prez-as-adoc-plugin.js +114 -0
@@ -0,0 +1,114 @@
1
+ import {HTMLElement, parse as parseHTML, TextNode} from 'node-html-parser';
2
+ import {asciidoctor, BASE_OPTIONS, HELPERS, REGISTRY} from "@tblaisot/asciidoctor-js-templates";
3
+ import * as path from "path";
4
+ import * as url from 'url';
5
+ import * as slidesTreeprocessor from "../../asciidoctor/extensions/slides_treeprocessor.js";
6
+ import * as speakerNotesTreeprocessor from "../../asciidoctor/extensions/speaker_notes_treeprocessor.js";
7
+
8
+ const {$, isEmptyString} = HELPERS;
9
+ const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
10
+
11
+ slidesTreeprocessor.register(REGISTRY);
12
+ speakerNotesTreeprocessor.register(REGISTRY);
13
+
14
+ function getFavicon(node) {
15
+ let favicon = ''
16
+ if (node.document.hasAttribute('favicon')) {
17
+ let icon_href = node.document.getAttribute('favicon');
18
+ if (isEmptyString(icon_href)) {
19
+ icon_href = 'favicon.ico';
20
+ }
21
+ const icon_ext = icon_href.split('.').pop();
22
+ const icon_type = icon_ext === 'ico' ? 'image/x-icon' : `image/${icon_ext}`;
23
+ favicon = $('link', {rel: "icon", type: icon_type, href: icon_href});
24
+ }
25
+ return favicon
26
+ }
27
+
28
+ function appendMetaIf(node_head, name, content) {
29
+ if (!isEmptyString(content)) {
30
+ const meta = new HTMLElement('meta', {});
31
+ meta.setAttribute(name, content);
32
+ node_head.appendChild(meta);
33
+ }
34
+ }
35
+
36
+ function setAttributeIf(node, name, content) {
37
+ if (!isEmptyString(content)) {
38
+ node.setAttribute(name, content);
39
+ }
40
+ }
41
+
42
+ function transformIndexHtml(
43
+ {
44
+ asciidoctorTemplatesOverloads,
45
+ baseDir = './src',
46
+ toDir = './dist',
47
+ slidesTemplates = []
48
+ },
49
+ html,
50
+ {filename}
51
+ ) {
52
+ const file = filename.replace(/\.html$/, '.adoc');
53
+ const document = parseHTML(html);
54
+
55
+
56
+ const template_dirs = [...BASE_OPTIONS.template_dirs, path.resolve(__dirname, '../../asciidoctor/templates')]
57
+ if (asciidoctorTemplatesOverloads && asciidoctorTemplatesOverloads.length > 0) {
58
+ asciidoctorTemplatesOverloads.forEach(overload => {
59
+ template_dirs.push(path.resolve(process.cwd(), overload));
60
+ })
61
+
62
+ }
63
+ const base_dir = path.resolve(process.cwd(), baseDir);
64
+ const to_dir = path.resolve(process.cwd(), toDir);
65
+
66
+ const OPTIONS = {
67
+ ...BASE_OPTIONS,
68
+ attributes: {
69
+ ...BASE_OPTIONS.attributes,
70
+ 'slide-template-dirs': slidesTemplates.map(p => path.resolve(process.cwd(), p))
71
+ },
72
+ template_dirs,
73
+ base_dir,
74
+ to_dir,
75
+ }
76
+
77
+ const adoc = asciidoctor.loadFile(file, OPTIONS);
78
+ const content = adoc.convert();
79
+ // console.log(adoc.getAttributes())
80
+
81
+ const node_html = document.querySelector('html');
82
+ const node_head = document.querySelector('head');
83
+ const node_body = document.querySelector('body');
84
+ node_html.setAttribute('lang', adoc.hasAttribute('nolang') ? '' : adoc.getAttribute('lang', 'en'))
85
+ const title = new HTMLElement('title', {});
86
+ title.appendChild(new TextNode(adoc.getDoctitle() || adoc.getAttribute('untitled-label')));
87
+ node_head.appendChild(title);
88
+ node_head.appendChild(parseHTML(getFavicon(adoc)));
89
+
90
+ appendMetaIf(node_head, 'application-name', adoc.getAttribute('app-name'));
91
+ appendMetaIf(node_head, 'author', adoc.getAttribute('authors'));
92
+ appendMetaIf(node_head, 'copyright', adoc.getAttribute('copyright'));
93
+ appendMetaIf(node_head, 'description', adoc.getAttribute('description'));
94
+ appendMetaIf(node_head, 'keywords', adoc.getAttribute('keywords'));
95
+ appendMetaIf(node_head, 'generator', `Asciidoctor ${adoc.getAttribute('asciidoctor-version')}`);
96
+
97
+ setAttributeIf(node_body, 'id', adoc.getId());
98
+ setAttributeIf(node_body, 'class', [
99
+ adoc.getAttribute('doctype'),
100
+ adoc.getAttribute('docrole') || adoc.getAttribute('role'),
101
+ ].join(' '));
102
+
103
+ document.querySelector('.slides').appendChild(parseHTML(content));
104
+
105
+ return document.toString();
106
+ }
107
+
108
+ export const prezAsAdocPlugin = (options) => {
109
+ return {
110
+ name: 'prez-as-adoc',
111
+ transformIndexHtml: transformIndexHtml.bind(null, options),
112
+ enforce: 'pre'
113
+ }
114
+ }