@asciidoctor/core 3.0.4 → 4.0.0-alpha.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.
Files changed (92) hide show
  1. package/README.md +42 -10
  2. package/build/browser/index.js +24156 -0
  3. package/build/node/index.cjs +24737 -0
  4. package/{dist/css/asciidoctor.css → data/asciidoctor-default.css} +54 -53
  5. package/package.json +55 -97
  6. package/src/abstract_block.js +857 -0
  7. package/src/abstract_node.js +954 -0
  8. package/src/attribute_entry.js +12 -0
  9. package/src/attribute_list.js +380 -0
  10. package/src/block.js +168 -0
  11. package/src/browser/asset.js +22 -0
  12. package/src/browser/reader.js +138 -0
  13. package/src/browser.js +121 -0
  14. package/src/callouts.js +85 -0
  15. package/src/compliance.js +54 -0
  16. package/src/constants.js +665 -0
  17. package/src/convert.js +370 -0
  18. package/src/converter/composite.js +83 -0
  19. package/src/converter/docbook5.js +1031 -0
  20. package/src/converter/html5.js +1893 -0
  21. package/src/converter/manpage.js +935 -0
  22. package/src/converter/template.js +459 -0
  23. package/src/converter.js +478 -0
  24. package/src/data/stylesheet-data.js +2 -0
  25. package/src/document.js +2134 -0
  26. package/src/extensions.js +1952 -0
  27. package/src/footnote.js +28 -0
  28. package/src/helpers.js +355 -0
  29. package/src/index.js +138 -0
  30. package/src/inline.js +158 -0
  31. package/src/list.js +240 -0
  32. package/src/load.js +276 -0
  33. package/src/logging.js +526 -0
  34. package/src/parser.js +3661 -0
  35. package/src/path_resolver.js +472 -0
  36. package/src/reader.js +1755 -0
  37. package/src/rx.js +829 -0
  38. package/src/section.js +354 -0
  39. package/src/stylesheets.js +30 -0
  40. package/src/substitutors.js +2241 -0
  41. package/src/syntaxHighlighter/highlightjs.js +90 -0
  42. package/src/syntaxHighlighter/html_pipeline.js +33 -0
  43. package/src/syntax_highlighter.js +304 -0
  44. package/src/table.js +952 -0
  45. package/src/timings.js +78 -0
  46. package/types/abstract_block.d.ts +346 -0
  47. package/types/abstract_node.d.ts +471 -0
  48. package/types/attribute_entry.d.ts +7 -0
  49. package/types/attribute_list.d.ts +52 -0
  50. package/types/block.d.ts +55 -0
  51. package/types/browser/asset.d.ts +7 -0
  52. package/types/browser/reader.d.ts +29 -0
  53. package/types/callouts.d.ts +36 -0
  54. package/types/compliance.d.ts +23 -0
  55. package/types/constants.d.ts +268 -0
  56. package/types/convert.d.ts +34 -0
  57. package/types/converter/composite.d.ts +20 -0
  58. package/types/converter/docbook5.d.ts +41 -0
  59. package/types/converter/html5.d.ts +51 -0
  60. package/types/converter/manpage.d.ts +59 -0
  61. package/types/converter/template.d.ts +83 -0
  62. package/types/converter.d.ts +150 -0
  63. package/types/data/stylesheet-data.d.ts +2 -0
  64. package/types/document.d.ts +495 -0
  65. package/types/extensions.d.ts +876 -0
  66. package/types/footnote.d.ts +18 -0
  67. package/types/helpers.d.ts +146 -0
  68. package/types/index.d.cts +75 -0
  69. package/types/index.d.ts +73 -3731
  70. package/types/inline.d.ts +69 -0
  71. package/types/list.d.ts +114 -0
  72. package/types/load.d.ts +39 -0
  73. package/types/logging.d.ts +187 -0
  74. package/types/parser.d.ts +114 -0
  75. package/types/path_resolver.d.ts +103 -0
  76. package/types/reader.d.ts +184 -0
  77. package/types/rx.d.ts +513 -0
  78. package/types/section.d.ts +122 -0
  79. package/types/stylesheets.d.ts +10 -0
  80. package/types/substitutors.d.ts +208 -0
  81. package/types/syntaxHighlighter/highlightjs.d.ts +33 -0
  82. package/types/syntaxHighlighter/html_pipeline.d.ts +16 -0
  83. package/types/syntax_highlighter.d.ts +167 -0
  84. package/types/table.d.ts +231 -0
  85. package/types/timings.d.ts +25 -0
  86. package/types/tsconfig.json +9 -0
  87. package/LICENSE +0 -21
  88. package/dist/browser/asciidoctor.js +0 -47654
  89. package/dist/browser/asciidoctor.min.js +0 -1452
  90. package/dist/graalvm/asciidoctor.js +0 -47402
  91. package/dist/node/asciidoctor.cjs +0 -21567
  92. package/dist/node/asciidoctor.js +0 -23037
@@ -0,0 +1,138 @@
1
+ // Browser-specific include path resolution for PreprocessorReader.
2
+ //
3
+ // This module implements the logic described in docs/modules/test/pages/browser-include-test.adoc
4
+ // and mirrors packages/core/lib/asciidoctor/js/asciidoctor_ext/browser/reader.rb.
5
+ //
6
+ // This logic is specific to Asciidoctor.js and has no equivalent in the upstream Ruby asciidoctor
7
+ // implementation. It handles the case where the document is loaded in a browser environment
8
+ // (XMLHttpRequest / Fetch IO module) where paths can be file:// or http(s):// URIs.
9
+ //
10
+ // The key behavioural differences from the standard file-system resolver:
11
+ // - Relative targets are resolved by string concatenation against a URI context dir,
12
+ // not via OS path normalisation.
13
+ // - Absolute paths (e.g. /foo/bar) are rewritten to file:///foo/bar.
14
+ // - All resolved includes are fetched via the Fetch API (targetType 'uri').
15
+ //
16
+ // Public API
17
+ // ----------
18
+ // resolveBrowserIncludePath(reader, target, attrlist)
19
+ // reader - a PreprocessorReader instance (provides _document, includeStack, _dir,
20
+ // replaceNextLine)
21
+ // target - the raw include target string
22
+ // attrlist - the raw attribute list string (used for error-message link construction)
23
+ //
24
+ // Returns [incPath, relpath] on success, where:
25
+ // incPath - the absolute URI to fetch
26
+ // relpath - the path relative to the document base dir (used for include tracking)
27
+ // Returns true/false when the include directive line has already been consumed/replaced
28
+ // (mirrors the Boolean return convention used by _resolveIncludePath in reader.js).
29
+
30
+ import { isUriish } from '../helpers.js'
31
+
32
+ /**
33
+ * Build the `link:...[...]` replacement text for a disallowed include.
34
+ * @param {object} reader
35
+ * @param {string} target
36
+ * @param {string|null} attrlist
37
+ * @returns {string}
38
+ * @internal
39
+ */
40
+ function _linkReplacement(reader, target, attrlist) {
41
+ const doc = reader._document
42
+ const lt = target.includes(' ') ? `pass:c[${target}]` : target
43
+ const la = doc.hasAttribute('compat-mode')
44
+ ? (attrlist ?? '')
45
+ : `role=include${attrlist ? `,${attrlist}` : ''}`
46
+ return `link:${lt}[${la}]`
47
+ }
48
+
49
+ /**
50
+ * Resolve an include path in a browser (URI-based) environment.
51
+ *
52
+ * Implements the rules from the browser-include-test, in the same order:
53
+ *
54
+ * Top-level include (includeStack is empty):
55
+ * 1. target starts with file:// → inc_path = relpath = target
56
+ * 2. target is a URI → must descend from baseDir or allow-uri-read; else → link
57
+ * 3. target is an absolute OS path → prepend file:// (or file:///)
58
+ * 4. baseDir == '.' → inc_path = relpath = target (resolved by XMLHttpRequest/fetch)
59
+ * 5. baseDir starts with file:// OR baseDir is not a URI → inc_path = baseDir/target; relpath = target
60
+ * 6. baseDir is an absolute URL → inc_path = baseDir/target; relpath = target
61
+ *
62
+ * Nested include (includeStack is non-empty):
63
+ * Rules 1–3 same as top-level.
64
+ * 4. parentDir == '.' → inc_path = relpath = target
65
+ * 5. parentDir starts with file:// OR parentDir is not a URI
66
+ * → inc_path = parentDir/target
67
+ * → relpath = inc_path if baseDir=='.' or inc_path not under baseDir, else path difference
68
+ * 6. parentDir is an absolute URL
69
+ * → must descend from baseDir or allow-uri-read; else → link
70
+ * → inc_path = parentDir/target
71
+ * → relpath = path difference if parentDir descends from baseDir, else target
72
+ * @param {object} reader - a PreprocessorReader instance
73
+ * @param {string} target - the raw include target string
74
+ * @param {string|null} attrlist - the raw attribute list string
75
+ * @returns {[string, string]|boolean} [incPath, relpath] on success, or boolean when the line was consumed.
76
+ */
77
+ export function resolveBrowserIncludePath(reader, target, attrlist) {
78
+ const doc = reader._document
79
+ const pathResolver = doc.pathResolver
80
+ // Normalise backslashes (Ruby: PathResolver.new('\\').posixify target)
81
+ const pTarget = target.replace(/\\/g, '/')
82
+ const baseDir = doc.baseDir
83
+ const topLevel = reader.includeStack.length === 0
84
+ const ctxDir = topLevel ? baseDir : reader._dir
85
+
86
+ let incPath, relpath
87
+
88
+ // ── Rule 1: target starts with file:// ────────────────────────────────────
89
+ if (pTarget.startsWith('file://')) {
90
+ incPath = relpath = pTarget
91
+
92
+ // ── Rule 2: target is an absolute URL (http:// / https:// / …) ───────────
93
+ } else if (isUriish(pTarget)) {
94
+ const descends = pathResolver.descendsFrom(pTarget, baseDir)
95
+ if (descends === false && !doc.getAttribute('allow-uri-read')) {
96
+ return reader.replaceNextLine(_linkReplacement(reader, target, attrlist))
97
+ }
98
+ incPath = relpath = pTarget
99
+
100
+ // ── Rule 3: target is an absolute OS path ─────────────────────────────────
101
+ } else if (pathResolver.absolutePath(pTarget)) {
102
+ incPath = relpath = `file://${pTarget.startsWith('/') ? '' : '/'}${pTarget}`
103
+
104
+ // ── Rule 4: context dir is '.' ────────────────────────────────────────────
105
+ // Relative path resolved by fetch relative to window.location / request origin.
106
+ } else if (ctxDir === '.') {
107
+ incPath = relpath = pTarget
108
+
109
+ // ── Rule 5: context dir is file:// OR a non-URI (regular OS path) ─────────
110
+ } else if (ctxDir.startsWith('file://') || !isUriish(ctxDir)) {
111
+ incPath = `${ctxDir}/${pTarget}`
112
+ if (topLevel) {
113
+ relpath = pTarget
114
+ } else {
115
+ const offset = pathResolver.descendsFrom(incPath, baseDir)
116
+ if (baseDir === '.' || offset === false) {
117
+ relpath = incPath
118
+ } else {
119
+ relpath = incPath.slice(offset)
120
+ }
121
+ }
122
+
123
+ // ── Rule 6: context dir is an absolute URL ────────────────────────────────
124
+ } else if (topLevel) {
125
+ incPath = `${ctxDir}/${(relpath = pTarget)}`
126
+ } else {
127
+ // Nested include: context dir is an absolute URL.
128
+ const ctxDescends = pathResolver.descendsFrom(ctxDir, baseDir)
129
+ if (ctxDescends !== false || doc.getAttribute('allow-uri-read')) {
130
+ incPath = `${ctxDir}/${pTarget}`
131
+ relpath = ctxDescends !== false ? incPath.slice(ctxDescends) : pTarget
132
+ } else {
133
+ return reader.replaceNextLine(_linkReplacement(reader, target, attrlist))
134
+ }
135
+ }
136
+
137
+ return [incPath, relpath]
138
+ }
package/src/browser.js ADDED
@@ -0,0 +1,121 @@
1
+ import packageJson from '../package.json' with { type: 'json' }
2
+ import { load as _load } from './load.js'
3
+ import { convert } from './convert.js'
4
+ import {
5
+ Document,
6
+ DocumentTitle,
7
+ Author,
8
+ Footnote,
9
+ ImageReference,
10
+ RevisionInfo,
11
+ } from './document.js'
12
+ import { Logger, LoggerManager, MemoryLogger, NullLogger } from './logging.js'
13
+ import { SafeMode, ContentModel } from './constants.js'
14
+ import { Timings } from './timings.js'
15
+ import { AbstractNode } from './abstract_node.js'
16
+ import { AbstractBlock } from './abstract_block.js'
17
+ import {
18
+ Registry,
19
+ Processor,
20
+ ProcessorExtension,
21
+ Preprocessor,
22
+ TreeProcessor,
23
+ Postprocessor,
24
+ IncludeProcessor,
25
+ DocinfoProcessor,
26
+ BlockProcessor,
27
+ InlineMacroProcessor,
28
+ BlockMacroProcessor,
29
+ Extensions,
30
+ } from './extensions.js'
31
+ import {
32
+ Converter,
33
+ DefaultFactory as DefaultConverterFactory,
34
+ } from './converter.js'
35
+ import { Inline } from './inline.js'
36
+ import { Block } from './block.js'
37
+ import { List, ListItem } from './list.js'
38
+ import { Section } from './section.js'
39
+ import { Cursor, Reader } from './reader.js'
40
+ import Html5Converter from './converter/html5.js'
41
+ import {
42
+ SyntaxHighlighter,
43
+ SyntaxHighlighterBase,
44
+ DefaultFactory as DefaultSyntaxHighlighterFactory,
45
+ } from './syntax_highlighter.js'
46
+
47
+ const ASCIIDOCTOR_CORE_VERSION = '2.0.26'
48
+
49
+ /**
50
+ * Get the version of Asciidoctor.js.
51
+ *
52
+ * @returns {string} - the version of Asciidoctor.js
53
+ */
54
+ export function getVersion() {
55
+ return packageJson.version
56
+ }
57
+
58
+ /**
59
+ * Get Asciidoctor core version number.
60
+ *
61
+ * @returns {string} - the version of Asciidoctor core (Ruby)
62
+ */
63
+ export function getCoreVersion() {
64
+ return ASCIIDOCTOR_CORE_VERSION
65
+ }
66
+
67
+ /**
68
+ * Parse the AsciiDoc source input into a Document.
69
+ *
70
+ * @param {string|string[]|Buffer} input - the AsciiDoc source as a String, String Array, or Buffer
71
+ * @param {Object} [options={}] - a plain object of options to control processing
72
+ * @returns {Promise<Document>} - the parsed Document
73
+ */
74
+ export async function load(input, options = {}) {
75
+ return _load(input, options)
76
+ }
77
+
78
+ export { convert }
79
+
80
+ export {
81
+ Document,
82
+ DocumentTitle,
83
+ Author,
84
+ Footnote,
85
+ ImageReference,
86
+ RevisionInfo,
87
+ Logger,
88
+ AbstractNode,
89
+ AbstractBlock,
90
+ Inline,
91
+ Block,
92
+ List,
93
+ ListItem,
94
+ Section,
95
+ Reader,
96
+ SyntaxHighlighterBase,
97
+ LoggerManager,
98
+ MemoryLogger,
99
+ NullLogger,
100
+ SafeMode,
101
+ ContentModel,
102
+ Timings,
103
+ Registry,
104
+ Processor,
105
+ ProcessorExtension,
106
+ Preprocessor,
107
+ TreeProcessor,
108
+ Postprocessor,
109
+ IncludeProcessor,
110
+ DocinfoProcessor,
111
+ BlockProcessor,
112
+ InlineMacroProcessor,
113
+ BlockMacroProcessor,
114
+ Extensions,
115
+ Cursor,
116
+ Converter as ConverterFactory,
117
+ DefaultConverterFactory,
118
+ DefaultSyntaxHighlighterFactory,
119
+ Html5Converter,
120
+ SyntaxHighlighter,
121
+ }
@@ -0,0 +1,85 @@
1
+ // ESM conversion of callouts.rb
2
+
3
+ /** Maintains a catalog of callouts and their associations. */
4
+ export class Callouts {
5
+ constructor() {
6
+ /** @internal */
7
+ this._lists = []
8
+ /** @internal */
9
+ this._listIndex = 0
10
+ this.nextList()
11
+ }
12
+
13
+ /**
14
+ * Register a new callout for the given list item ordinal.
15
+ * @param {number} liOrdinal - The 1-based ordinal of the list item.
16
+ * @returns {string} The unique id of this callout (e.g. 'CO1-1').
17
+ */
18
+ register(liOrdinal) {
19
+ const id = this._generateNextCalloutId()
20
+ this.getCurrentList().push({ ordinal: parseInt(liOrdinal, 10), id })
21
+ this._coIndex++
22
+ return id
23
+ }
24
+
25
+ /**
26
+ * Get the next callout id in document order (used during conversion).
27
+ * @returns {string|null} The unique id of the next callout, or null.
28
+ */
29
+ readNextId() {
30
+ const list = this.getCurrentList()
31
+ const id = this._coIndex <= list.length ? list[this._coIndex - 1].id : null
32
+ this._coIndex++
33
+ return id
34
+ }
35
+
36
+ /**
37
+ * Get a space-separated list of callout ids for the given list item.
38
+ * @param {number} liOrdinal - The 1-based ordinal of the list item.
39
+ * @returns {string} Space-separated callout ids.
40
+ */
41
+ getCalloutIds(liOrdinal) {
42
+ const list = this.getCurrentList()
43
+ return list
44
+ .filter((item) => item.ordinal === liOrdinal)
45
+ .map((item) => item.id)
46
+ .join(' ')
47
+ }
48
+
49
+ /** @returns {Array<{ordinal: number, id: string}>} The callout objects at the current list index. */
50
+ getCurrentList() {
51
+ return this._lists[this._listIndex - 1]
52
+ }
53
+
54
+ /** @returns {Array<Array<{ordinal: number, id: string}>>} All callout lists in the document. */
55
+ getLists() {
56
+ return this._lists
57
+ }
58
+
59
+ /** @returns {number} The 1-based index of the current callout list. */
60
+ getListIndex() {
61
+ return this._listIndex
62
+ }
63
+
64
+ /** Advance to the next callout list in the document. */
65
+ nextList() {
66
+ this._listIndex++
67
+ if (this._lists.length < this._listIndex) this._lists.push([])
68
+ /** @internal */
69
+ this._coIndex = 1
70
+ }
71
+
72
+ /** Rewind the list pointer to the beginning (switching parse → convert). */
73
+ rewind() {
74
+ this._listIndex = 1
75
+ this._coIndex = 1
76
+ }
77
+
78
+ /**
79
+ * @internal
80
+ * @private
81
+ */
82
+ _generateNextCalloutId() {
83
+ return `CO${this._listIndex}-${this._coIndex}`
84
+ }
85
+ }
@@ -0,0 +1,54 @@
1
+ // ESM conversion of the Compliance module (defined inside asciidoctor.rb).
2
+ //
3
+ // Ruby-to-JavaScript notes:
4
+ // - The Ruby module uses dynamic attr_accessor generation via `define`.
5
+ // In JS each flag is a plain enumerable property on the exported object.
6
+ // - The `keys` Set is retained so callers can enumerate all known flags
7
+ // (used e.g. by the options-merging code in Document).
8
+ // - All default values match the Asciidoctor defaults (not the "AsciiDoc
9
+ // compliance values" documented in comments — those differ intentionally).
10
+
11
+ export const Compliance = {
12
+ keys: new Set([
13
+ 'blockTerminatesParagraph',
14
+ 'strictVerbatimParagraphs',
15
+ 'underlineStyleSectionTitles',
16
+ 'unwrapStandalonePreamble',
17
+ 'attributeMissing',
18
+ 'attributeUndefined',
19
+ 'shorthandPropertySyntax',
20
+ 'naturalXrefs',
21
+ 'uniqueIdStartIndex',
22
+ 'markdownSyntax',
23
+ ]),
24
+
25
+ /** AsciiDoc terminates paragraphs adjacent to block content (delimiter or block attribute list). Compliance value: true */
26
+ blockTerminatesParagraph: true,
27
+
28
+ /** AsciiDoc does not parse paragraphs with a verbatim style as verbatim content. Compliance value: false (Asciidoctor default: true) */
29
+ strictVerbatimParagraphs: true,
30
+
31
+ /** AsciiDoc supports both atx (single-line) and setext (underlined) section titles. Compliance value: true */
32
+ underlineStyleSectionTitles: true,
33
+
34
+ /** Asciidoctor will unwrap the content in a preamble if the document has a title and no sections. Compliance value: false (Asciidoctor default: true) */
35
+ unwrapStandalonePreamble: true,
36
+
37
+ /** AsciiDoc drops lines that contain references to missing attributes. Possible values: 'skip', 'drop', 'drop-line', 'warn'. Compliance value: 'drop-line' (Asciidoctor default: 'skip') */
38
+ attributeMissing: 'skip',
39
+
40
+ /** AsciiDoc drops lines that contain an attribute unassignment. Compliance value: 'drop-line' */
41
+ attributeUndefined: 'drop-line',
42
+
43
+ /** Shorthand syntax for id, role and options on blocks (e.g. #id.role%opt). Compliance value: false (Asciidoctor default: true) */
44
+ shorthandPropertySyntax: true,
45
+
46
+ /** Resolve cross-reference targets by matching reftext or title. Compliance value: false (Asciidoctor default: true) */
47
+ naturalXrefs: true,
48
+
49
+ /** Starting counter when generating a unique id on conflict. Compliance value: 2 */
50
+ uniqueIdStartIndex: 2,
51
+
52
+ /** Recognize commonly-used Markdown syntax where it does not conflict. Compliance value: false (Asciidoctor default: true) */
53
+ markdownSyntax: true,
54
+ }