raindown 0.23.0 → 0.25.0
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.
- checksums.yaml +4 -4
- data/lib/raindown/bare_directives.rb +5 -3
- data/lib/raindown/code.rb +4 -1
- data/lib/raindown/editing.rb +2 -2
- data/lib/raindown/edition.rb +52 -0
- data/lib/raindown/features.rb +121 -0
- data/lib/raindown/js/action.js +4 -1
- data/lib/raindown/js/editing.js +25 -4
- data/lib/raindown/markdown_nodes.rb +3 -2
- data/lib/raindown/node_blocks.rb +13 -4
- data/lib/raindown/node_injector.rb +3 -1
- data/lib/raindown/nodes.rb +16 -40
- data/lib/raindown/pre_renderer.rb +4 -4
- data/lib/raindown/project_nodes.rb +2 -0
- data/lib/raindown/projects.rb +3 -3
- data/lib/raindown/rasters.rb +1 -0
- data/lib/raindown/rewriter.rb +6 -5
- data/lib/raindown/ruby_nodes.rb +40 -0
- data/lib/raindown/table/table_file.rb +4 -0
- data/lib/raindown.rb +1 -2
- data/lib/version.rb +1 -1
- metadata +4 -2
- data/lib/elements.rb +0 -45
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bc887b24979a4ce7c3c33e3862357d94ff411ba32f8583f143647853298e89ea
|
|
4
|
+
data.tar.gz: cf3c584623f6717a461c97aead55efa4f68a708cab71fb5bf64af1f1b47e5b90
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9bfe90547203e8899d8bfd15068f33da8c3b6802330307664bca447490857f67da9e481f8b4d814ad89062455e306449edc494d084b0f53795af7b94a9e8cd5a
|
|
7
|
+
data.tar.gz: 60ea396312d5a8cac4ef4e08ef629136023200d989a0056fc7641185b019ff5bca936fc6a61a5777c2065cff4fda49fc847be8cf73a0ffc8efe18177e2ecc96c
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative 'code_blocks'
|
|
4
4
|
require_relative 'directives'
|
|
5
|
-
require_relative '
|
|
5
|
+
require_relative 'edition'
|
|
6
6
|
require_relative 'front_matter'
|
|
7
7
|
|
|
8
8
|
module Raindown
|
|
@@ -68,8 +68,10 @@ module Raindown
|
|
|
68
68
|
# Returns the index of the last line it handled. That's the directive itself, so the lines it holds
|
|
69
69
|
# are expanded too, and a bare directive inside it closes before it does.
|
|
70
70
|
def expand_line(lines, index)
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
Raindown.edition.plugs(:schema_block).each do |schemas|
|
|
72
|
+
schema = schemas.at(lines, index, bare: true)
|
|
73
|
+
return expand_schema(lines, index, schema) if schema
|
|
74
|
+
end
|
|
73
75
|
|
|
74
76
|
match = lines[index].match(LINE)
|
|
75
77
|
return index unless match
|
data/lib/raindown/code.rb
CHANGED
|
@@ -12,7 +12,8 @@ module Raindown
|
|
|
12
12
|
module_function
|
|
13
13
|
|
|
14
14
|
# Byte ranges of code in the Markdown, from Commonmarker's line and column positions, or rendering Markdown, which
|
|
15
|
-
# doesn't load Commonmarker,
|
|
15
|
+
# doesn't load Commonmarker, or without it, like in WebAssembly, where the Obsidian plugin writes back a Markdown
|
|
16
|
+
# Component's template, its fenced blocks and code spans.
|
|
16
17
|
def ranges(markdown)
|
|
17
18
|
return scanned_ranges(markdown) unless Raindown.commonmark?
|
|
18
19
|
|
|
@@ -24,6 +25,8 @@ module Raindown
|
|
|
24
25
|
end
|
|
25
26
|
|
|
26
27
|
ranges
|
|
28
|
+
rescue LoadError
|
|
29
|
+
scanned_ranges(markdown)
|
|
27
30
|
end
|
|
28
31
|
|
|
29
32
|
# The byte offset each line starts at, and the end's.
|
data/lib/raindown/editing.rb
CHANGED
|
@@ -18,7 +18,7 @@ module Raindown
|
|
|
18
18
|
# Without commonmark, it's Markdown, for the editor to render itself.
|
|
19
19
|
def render_markdown(markdown, path:, bare: false, commonmark: true)
|
|
20
20
|
Nodes.load(path)
|
|
21
|
-
Raindown.render(markdown:, metadata:
|
|
21
|
+
Raindown.render(markdown:, metadata: Raindown.edition.metadata(path), bare: bare || BareDirectives.file?(path), commonmark:,
|
|
22
22
|
**Config.render_options(path))
|
|
23
23
|
end
|
|
24
24
|
|
|
@@ -27,7 +27,7 @@ module Raindown
|
|
|
27
27
|
def rewrite_markdown(markdown, path:, bare: false, execute: false, actions: [])
|
|
28
28
|
load_errors = Nodes.load(path)
|
|
29
29
|
markdown = acted(markdown, actions, path:, bare:)
|
|
30
|
-
rewrite = Rewriter.rewrite(content: markdown, path:, bare:, execute:, metadata:
|
|
30
|
+
rewrite = Rewriter.rewrite(content: markdown, path:, bare:, execute:, metadata: Raindown.edition.metadata(path))
|
|
31
31
|
failures = rewrite.failures.map { "Endpoint check failed: #{it}" }
|
|
32
32
|
{ output: rewrite.content, warnings: load_errors + failures + rewrite.problems }
|
|
33
33
|
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'features'
|
|
4
|
+
|
|
5
|
+
module Raindown
|
|
6
|
+
# What a product built on Raindown does with it, set before any note's written, as the features it has: Raindown
|
|
7
|
+
# itself, with all of them, and a project's components in its .raindown folder, or Components, the Obsidian plugin
|
|
8
|
+
# for beginners, with only Markdown Components, in a vault's Components folder, which Obsidian shows, so the rest of a
|
|
9
|
+
# note, like a table, stays as it's written. Only the features an edition has load.
|
|
10
|
+
class Edition
|
|
11
|
+
attr_reader :folder
|
|
12
|
+
|
|
13
|
+
def initialize(folder:, features:)
|
|
14
|
+
@folder = folder
|
|
15
|
+
@features = Features[*features]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# What its features have of a kind, like components, loaded the first time they're asked for, and kept, as some are
|
|
19
|
+
# asked for on each line.
|
|
20
|
+
def plugs(key)
|
|
21
|
+
@plugs ||= {}
|
|
22
|
+
return @plugs[key] if @plugs.key?(key)
|
|
23
|
+
return @plugs[key] = [] unless @features.key?(key)
|
|
24
|
+
|
|
25
|
+
@plugs[key] = @features[key].to_a
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# The notes list: lists and wiki links link to, beside the file, when it has them, or none.
|
|
29
|
+
def metadata(path)
|
|
30
|
+
pages = plugs(:pages).first
|
|
31
|
+
return NoMetadata unless pages
|
|
32
|
+
|
|
33
|
+
pages.for(path)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Its write-in nodes' and endpoints' lexemes and nodes, for Antlers.
|
|
37
|
+
def elements
|
|
38
|
+
@features[:lexeme, :node]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
FULL = new(folder: '.raindown', features: %i[write_in code_components markdown_components built_ins pages endpoints schemas tables])
|
|
42
|
+
COMPONENTS = new(folder: 'Components', features: %i[write_in markdown_components])
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
class << self
|
|
46
|
+
attr_writer :edition
|
|
47
|
+
|
|
48
|
+
def edition
|
|
49
|
+
@edition ||= Edition::FULL
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'plugs'
|
|
4
|
+
|
|
5
|
+
module Raindown
|
|
6
|
+
# What an edition can have, each loading its files the first time an edition that has it asks for it, so one that
|
|
7
|
+
# hasn't never loads them. Components are found in the order they're here: Ruby, then JavaScript, then Markdown.
|
|
8
|
+
class Features
|
|
9
|
+
include Plugs
|
|
10
|
+
|
|
11
|
+
# Write-in nodes, in <{ }>, like <{ Card }>, <{ :toc }> or <{ Card: }>...<{ :Card }>, rendered in the template pass.
|
|
12
|
+
plug(:write_in) do
|
|
13
|
+
plug(:lexeme) do
|
|
14
|
+
lazy do
|
|
15
|
+
require_relative '../lexemes/node_lexeme'
|
|
16
|
+
NodeLexeme
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# A list: block loops over its files, so it comes before other nodes' blocks.
|
|
21
|
+
plug(:node) do
|
|
22
|
+
lazy do
|
|
23
|
+
require_relative '../nodes/list_node'
|
|
24
|
+
ListNode
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
plug(:node) do
|
|
29
|
+
lazy do
|
|
30
|
+
require_relative '../nodes/write_in_node'
|
|
31
|
+
WriteInNode
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
plug(:node) do
|
|
36
|
+
lazy do
|
|
37
|
+
require_relative '../nodes/write_in_node'
|
|
38
|
+
SoloWriteInNode
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
plug(:code_components) do
|
|
44
|
+
plug(:components) do
|
|
45
|
+
lazy do
|
|
46
|
+
require_relative 'ruby_nodes'
|
|
47
|
+
RubyNodes
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
plug(:components) do
|
|
52
|
+
lazy do
|
|
53
|
+
require_relative 'js/js_nodes'
|
|
54
|
+
JSNodes
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
plug(:markdown_components) do
|
|
60
|
+
plug(:components) do
|
|
61
|
+
lazy do
|
|
62
|
+
require_relative 'markdown_nodes'
|
|
63
|
+
MarkdownNodes
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Raindown's own nodes, like toc:, each loaded the first time a note names it.
|
|
69
|
+
plug(:built_ins) do
|
|
70
|
+
lazy { Nodes::BUILT_INS }
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# A project's notes, which list: lists and wiki links link to, listed with Dirload.
|
|
74
|
+
plug(:pages) do
|
|
75
|
+
lazy { Pages }
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
plug(:endpoints) do
|
|
79
|
+
plug(:endpoint_runner) do
|
|
80
|
+
lazy do
|
|
81
|
+
require_relative 'endpoint/endpoint_runner'
|
|
82
|
+
EndpointRunner
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
plug(:lexeme) do
|
|
87
|
+
lazy do
|
|
88
|
+
require_relative '../lexemes/endpoint_lexeme'
|
|
89
|
+
EndpointLexeme
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
plug(:node) do
|
|
94
|
+
lazy do
|
|
95
|
+
require_relative '../nodes/endpoint_node'
|
|
96
|
+
EndpointNode
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# Schemas, like schema: User, which endpoints check responses against.
|
|
102
|
+
plug(:schemas) do
|
|
103
|
+
plug(:schema_block) do
|
|
104
|
+
lazy do
|
|
105
|
+
require_relative 'endpoint/schema_block'
|
|
106
|
+
SchemaBlock
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Lining up tables' columns as a note's written back.
|
|
112
|
+
plug(:tables) do
|
|
113
|
+
plug(:table_formatter) do
|
|
114
|
+
lazy do
|
|
115
|
+
require_relative 'table/table_formatter'
|
|
116
|
+
TableFormatter
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
data/lib/raindown/js/action.js
CHANGED
|
@@ -18,6 +18,9 @@ function raindownAfterAction(markdown, { line, column = null, set }, { bare = fa
|
|
|
18
18
|
String.raw`^( {0,3}<\{\s*(?::|(?=[A-Z]))${NAME}\s+)(.*?)\s*\}>[ \t]*$`
|
|
19
19
|
]
|
|
20
20
|
const BARE_DIRECTIVES = [String.raw`^( {0,3}${NAME}:[ \t]+)(.*?)[ \t]*$`, String.raw`^( {0,3}:${NAME}[ \t]+)(.*?)[ \t]*$`]
|
|
21
|
+
// A component's bare directive, by its capitalized name, which works anywhere, as NodeBlocks::COMPONENT_DIRECTIVES.
|
|
22
|
+
const COMPONENT = String.raw`[A-Z]\w*(?:::[A-Z]\w*)*`
|
|
23
|
+
const COMPONENT_DIRECTIVES = [String.raw`^( {0,3}${COMPONENT}:[ \t]+)(.*?)[ \t]*$`, String.raw`^( {0,3}:${COMPONENT}[ \t]+)(.*?)[ \t]*$`]
|
|
21
24
|
|
|
22
25
|
const lines = markdown.split('\n')
|
|
23
26
|
const text = lines[line]
|
|
@@ -31,7 +34,7 @@ function raindownAfterAction(markdown, { line, column = null, set }, { bare = fa
|
|
|
31
34
|
from = column + cell.length - cell.trimStart().length
|
|
32
35
|
to = from + cell.trim().length
|
|
33
36
|
}
|
|
34
|
-
let patterns = DIRECTIVES
|
|
37
|
+
let patterns = [...DIRECTIVES, ...COMPONENT_DIRECTIVES]
|
|
35
38
|
if (bare || column !== null) patterns = [...DIRECTIVES, ...BARE_DIRECTIVES]
|
|
36
39
|
const match = patterns.map((pattern) => text.slice(from, to).match(new RegExp(pattern))).find(Boolean)
|
|
37
40
|
if (!match) return markdown
|
data/lib/raindown/js/editing.js
CHANGED
|
@@ -19,12 +19,15 @@ const raindownEditing = (() => {
|
|
|
19
19
|
const BARE_SELF_CLOSING = /^( {0,3})(:toc)[ \t]*$/;
|
|
20
20
|
|
|
21
21
|
const BARE_OPEN = new RegExp(String.raw`^( {0,3})(${NAME}:)(?=[ \t]*$|[ \t]+\S)`);
|
|
22
|
+
// A component's bare directive, BookCard: or :BookCard, which works in every note, as only a component the project
|
|
23
|
+
// has starts one, so it's only a directive when it's named in components.
|
|
24
|
+
const COMPONENT_LINE = /^( {0,3})(:?)([A-Z]\w*(?:::[A-Z]\w*)*)(:?)(?=[ \t]*$|[ \t]+\S)/;
|
|
22
25
|
|
|
23
26
|
// Strings, {variables}, numbers, :flags, props like folder: or limit=, and words.
|
|
24
27
|
const ARGUMENT = /"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|\{[A-Za-z_][\w.]*\}|(?<![\w:])-?\d+(?:\.\d+)?\b|(?<![\w:]):[A-Za-z_][\w-]*|[A-Za-z_][\w-]*(?::(?![\w:])|=)|[A-Za-z_][\w.-]*/g;
|
|
25
28
|
|
|
26
29
|
// The highlighted parts of a note, in order, as { from, to, type }, where type is a class like cm-raindown-name.
|
|
27
|
-
function directiveTokens(text, { bare = false } = {}) {
|
|
30
|
+
function directiveTokens(text, { bare = false, components = [] } = {}) {
|
|
28
31
|
const front = /^---\n([\s\S]*?)\n---(?:\n|$)/.exec(text);
|
|
29
32
|
const bareHere = bare || /^raindown:\s*true\s*$/m.test(front?.[1] ?? '');
|
|
30
33
|
const tokens = [];
|
|
@@ -38,7 +41,7 @@ const raindownEditing = (() => {
|
|
|
38
41
|
} else if (marker) {
|
|
39
42
|
fence = marker;
|
|
40
43
|
} else {
|
|
41
|
-
tokens.push(...lineTokens(line, { bare: bareHere }).map((token) => ({ ...token, from: token.from + offset, to: token.to + offset })));
|
|
44
|
+
tokens.push(...lineTokens(line, { bare: bareHere, components }).map((token) => ({ ...token, from: token.from + offset, to: token.to + offset })));
|
|
42
45
|
}
|
|
43
46
|
offset += line.length + 1;
|
|
44
47
|
}
|
|
@@ -46,7 +49,7 @@ const raindownEditing = (() => {
|
|
|
46
49
|
return tokens.sort((a, b) => a.from - b.from);
|
|
47
50
|
}
|
|
48
51
|
|
|
49
|
-
function lineTokens(line, { bare }) {
|
|
52
|
+
function lineTokens(line, { bare, components }) {
|
|
50
53
|
const code = [...line.matchAll(/(`+)[^`]*?\1/g)].map((match) => [match.index, match.index + match[0].length]);
|
|
51
54
|
const tokens = [];
|
|
52
55
|
const add = (from, to, type) => {
|
|
@@ -65,7 +68,10 @@ const raindownEditing = (() => {
|
|
|
65
68
|
argumentTokens(match[1], match.index + 2, { antlers: true }, add);
|
|
66
69
|
add(end - 2, end, 'delimiter');
|
|
67
70
|
}
|
|
68
|
-
if (!bare)
|
|
71
|
+
if (!bare) {
|
|
72
|
+
addComponentTokens(line, components, add);
|
|
73
|
+
return tokens;
|
|
74
|
+
}
|
|
69
75
|
|
|
70
76
|
const selfClosing = BARE_SELF_CLOSING.exec(line);
|
|
71
77
|
const open = BARE_OPEN.exec(line);
|
|
@@ -79,6 +85,21 @@ const raindownEditing = (() => {
|
|
|
79
85
|
return tokens;
|
|
80
86
|
}
|
|
81
87
|
|
|
88
|
+
// Adds the tokens of a component's bare directive on the line, BookCard: with its arguments, or :BookCard, when it's
|
|
89
|
+
// one of components.
|
|
90
|
+
function addComponentTokens(line, components, add) {
|
|
91
|
+
const found = COMPONENT_LINE.exec(line);
|
|
92
|
+
if (!found || !components.includes(found[3]) || Boolean(found[2]) === Boolean(found[4])) return;
|
|
93
|
+
|
|
94
|
+
const [indent, name] = [found[1].length, found[2] + found[3] + found[4]];
|
|
95
|
+
if (found[2]) {
|
|
96
|
+
add(indent, indent + name.length, 'self-closing');
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
add(indent, indent + name.length, 'name');
|
|
100
|
+
argumentTokens(line.slice(indent + name.length), indent + name.length, { antlers: false }, add);
|
|
101
|
+
}
|
|
102
|
+
|
|
82
103
|
// The row of a table the cursor's in, with the |+ rows carrying it on: the lines it spans, the column the cursor's in,
|
|
83
104
|
// the line its table starts on, whether it's the header or the delimiter row below it, and the line of the row below
|
|
84
105
|
// it, or null outside a table's rows.
|
|
@@ -19,11 +19,12 @@ module Raindown
|
|
|
19
19
|
|
|
20
20
|
module_function
|
|
21
21
|
|
|
22
|
-
# Its templates are read as they're written, so loading one can't fail, and there are never errors to give.
|
|
22
|
+
# Its templates are read as they're written, so loading one can't fail, and there are never errors to give. The
|
|
23
|
+
# folder loaded last has the name, so each reads its own folder's template, not one loaded before from another.
|
|
23
24
|
def load(folder)
|
|
24
25
|
Dir.glob(EXTENSIONS.map { "*#{it}" }, base: folder).each do |file|
|
|
25
26
|
name = File.basename(file, '.*')
|
|
26
|
-
node_classes[name]
|
|
27
|
+
node_classes[name] = MarkdownNode.for(name:, path: File.join(folder, file)) if name.match?(NAME)
|
|
27
28
|
end
|
|
28
29
|
[]
|
|
29
30
|
end
|
data/lib/raindown/node_blocks.rb
CHANGED
|
@@ -19,8 +19,11 @@ module Raindown
|
|
|
19
19
|
# A bare :Changelog is write-in: it only renders, with its render, never its rewrite. In Antlers' delimiters, like
|
|
20
20
|
# <{ Changelog }>, it's write-in too, and the template pass renders it, as a WriteInNode, so it's only found here
|
|
21
21
|
# for a document's outline. toc: and list: are Raindown's own nodes. A name only starts a block when it's a loaded
|
|
22
|
-
# node, so other text like "Note:" is left alone.
|
|
23
|
-
#
|
|
22
|
+
# node, so other text like "Note:" is left alone. A component's directive, by its capitalized name, can be bare
|
|
23
|
+
# anywhere, as only a component the project has, like .raindown/BookCard.md, starts one, which it has on purpose, while
|
|
24
|
+
# Raindown's own, like toc:, list: and table:, which are common words, are bare only where bare directives work. There,
|
|
25
|
+
# a bare grid, a block starting with a rule like +---+, is a grid: without its directive, which it writes from its
|
|
26
|
+
# first line, its rule.
|
|
24
27
|
module NodeBlocks
|
|
25
28
|
class MissingEndTag < StandardError; end
|
|
26
29
|
class BrokenText < StandardError; end
|
|
@@ -34,6 +37,12 @@ module Raindown
|
|
|
34
37
|
BARE_SELF_CLOSING = /\A( {0,3}):(#{NAME})(?:[ \t]+(.*?))?[ \t]*$/
|
|
35
38
|
BARE_GRID = /\A {0,3}\+-[-+]*\+[ \t]*$/
|
|
36
39
|
DIRECTIVES = { open: OPEN, comment_open: COMMENT_OPEN, self_closing: SELF_CLOSING }.freeze
|
|
40
|
+
# A component's directive, by its capitalized name, bare, which works anywhere, as only one a project has starts one.
|
|
41
|
+
COMPONENT = '[A-Z]\\w*(?:::[A-Z]\\w*)*'
|
|
42
|
+
COMPONENT_DIRECTIVES = {
|
|
43
|
+
**DIRECTIVES, bare_open: /\A( {0,3})(#{COMPONENT}):(?:[ \t]+(.*?))?[ \t]*$/,
|
|
44
|
+
bare_self_closing: /\A( {0,3}):(#{COMPONENT})(?:[ \t]+(.*?))?[ \t]*$/
|
|
45
|
+
}.freeze
|
|
37
46
|
BARE_DIRECTIVES = { **DIRECTIVES, bare_open: BARE_OPEN, bare_self_closing: BARE_SELF_CLOSING }.freeze
|
|
38
47
|
# Unquoted text after name:, like YAML's, runs up to the next prop, so title: Hello world limit: 3 has two. A comma
|
|
39
48
|
# before the next prop, like data.csv, total: true, separates them like a space, while one in text, like Hello,
|
|
@@ -165,9 +174,9 @@ module Raindown
|
|
|
165
174
|
end
|
|
166
175
|
end
|
|
167
176
|
|
|
168
|
-
# The directive on the line and which kind it is, or nil.
|
|
177
|
+
# The directive on the line and which kind it is, or nil: bare only for a component, unless bare directives work.
|
|
169
178
|
def directive(line, bare:)
|
|
170
|
-
patterns =
|
|
179
|
+
patterns = COMPONENT_DIRECTIVES
|
|
171
180
|
patterns = BARE_DIRECTIVES if bare
|
|
172
181
|
patterns.each do |pattern, regexp|
|
|
173
182
|
match = line.match(regexp)
|
|
@@ -78,7 +78,9 @@ module Raindown
|
|
|
78
78
|
# costs about as much as a node. So they see the document as it was before the blocks wrote, not what the nodes
|
|
79
79
|
# below them just wrote. A host that can't be asked leaves each to be asked alone, to say why in its place.
|
|
80
80
|
def written_ahead(lines, blocks)
|
|
81
|
-
ahead = blocks.select { it[:node].
|
|
81
|
+
ahead = blocks.select { it[:node].respond_to?(:call_for) }
|
|
82
|
+
return {} if ahead.empty?
|
|
83
|
+
|
|
82
84
|
calls = ahead.map { it[:node].call_for(:rewrite, context_of(lines, it)) }
|
|
83
85
|
ahead.map { it[:open] }.zip(JSNodes.call(calls, metadata: @metadata)).to_h
|
|
84
86
|
rescue JSNodes::Error
|
data/lib/raindown/nodes.rb
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative 'edition'
|
|
3
4
|
require_relative 'fragments'
|
|
4
|
-
require_relative 'js/js_nodes'
|
|
5
|
-
require_relative 'markdown_nodes'
|
|
6
5
|
require_relative 'node'
|
|
7
6
|
require_relative 'problem'
|
|
7
|
+
require_relative 'services'
|
|
8
8
|
require_relative 'stat'
|
|
9
9
|
|
|
10
10
|
module Raindown
|
|
@@ -35,43 +35,21 @@ module Raindown
|
|
|
35
35
|
|
|
36
36
|
module_function
|
|
37
37
|
|
|
38
|
-
# Loads the .raindown folder beside the file or in the nearest directory above it,
|
|
39
|
-
# any of its files couldn't be loaded, like ".raindown/stars.rb:3:
|
|
40
|
-
# so one that can't be leaves the others loaded.
|
|
38
|
+
# Loads the .raindown folder beside the file or in the nearest directory above it, or the edition's own, like
|
|
39
|
+
# Components', once per process, and gives why any of its files couldn't be loaded, like ".raindown/stars.rb:3:
|
|
40
|
+
# syntax errors found". Each file loads on its own, so one that can't be leaves the others loaded. Only the kinds of
|
|
41
|
+
# components the edition has load, like only Markdown Components in Components.
|
|
41
42
|
def load(path)
|
|
42
43
|
folder = find_folder(File.dirname(File.expand_path(path)))
|
|
43
44
|
return [] if folder.nil?
|
|
44
45
|
return load_errors[folder] if loaded.include?(folder)
|
|
45
46
|
|
|
46
47
|
loaded << folder
|
|
47
|
-
load_errors[folder] =
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
# Dirload's steps, for the folder's Ruby files, as dirload(folder) takes them, a file that fails one being left out
|
|
51
|
-
# of the next, and why each failed.
|
|
52
|
-
def load_ruby(folder)
|
|
53
|
-
require 'lownode'
|
|
54
|
-
require 'dirload'
|
|
55
|
-
files = Dirload.file_paths(absolute_path: folder).map { [it, Dirload.find_adapter(file_path: it)] }
|
|
56
|
-
errors = {}
|
|
57
|
-
%i[mapload preload evaluate].each do |step|
|
|
58
|
-
files.each do |file, adapter|
|
|
59
|
-
next if adapter.nil? || errors.key?(file)
|
|
60
|
-
|
|
61
|
-
adapter.public_send(step, file_path: file)
|
|
62
|
-
rescue StandardError, ScriptError => e
|
|
63
|
-
errors[file] = e.message
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
errors.map { |file, message| load_error(folder, file, message) }
|
|
48
|
+
load_errors[folder] = load_folder(folder)
|
|
67
49
|
end
|
|
68
50
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
listed = file.delete_prefix("#{File.dirname(folder)}/")
|
|
72
|
-
return "#{listed}#{message.delete_prefix(file)}" if message.start_with?("#{file}:")
|
|
73
|
-
|
|
74
|
-
"#{listed}: #{message}"
|
|
51
|
+
def load_folder(folder)
|
|
52
|
+
Raindown.edition.plugs(:components).flat_map { it.load(folder) }
|
|
75
53
|
end
|
|
76
54
|
|
|
77
55
|
def load_errors
|
|
@@ -80,7 +58,7 @@ module Raindown
|
|
|
80
58
|
|
|
81
59
|
def find_folder(directory)
|
|
82
60
|
loop do
|
|
83
|
-
folder = File.join(directory,
|
|
61
|
+
folder = File.join(directory, Raindown.edition.folder)
|
|
84
62
|
return folder if File.directory?(folder)
|
|
85
63
|
|
|
86
64
|
parent = File.dirname(directory)
|
|
@@ -94,19 +72,17 @@ module Raindown
|
|
|
94
72
|
@loaded ||= []
|
|
95
73
|
end
|
|
96
74
|
|
|
97
|
-
# The node class a block names, when it's loaded.
|
|
75
|
+
# The node class a block names, when it's loaded, and Raindown's own, when the edition has them.
|
|
98
76
|
def node_class(name)
|
|
99
|
-
|
|
77
|
+
built_in = Raindown.edition.plugs(:built_ins).reduce({}, :merge)[name]
|
|
78
|
+
return loaded_class(name) unless built_in
|
|
100
79
|
|
|
101
|
-
loaded_class(
|
|
80
|
+
loaded_class(built_in) || Raindown.const_get(built_in)
|
|
102
81
|
end
|
|
103
82
|
|
|
104
|
-
#
|
|
83
|
+
# The first of the edition's kinds of components, in order, with a node of the name: Ruby, JavaScript, then Markdown.
|
|
105
84
|
def loaded_class(name)
|
|
106
|
-
|
|
107
|
-
return klass if node?(klass)
|
|
108
|
-
|
|
109
|
-
JSNodes.node_class(name) || MarkdownNodes.node_class(name)
|
|
85
|
+
Raindown.edition.plugs(:components).lazy.filter_map { it.node_class(name) }.first
|
|
110
86
|
end
|
|
111
87
|
|
|
112
88
|
# A LowNode, or one of Raindown's own nodes, that writes Markdown. In an app, LowNodes are also routes and pages,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'antlers'
|
|
4
|
-
require_relative '
|
|
4
|
+
require_relative 'edition'
|
|
5
5
|
require_relative 'bare_directives'
|
|
6
6
|
require_relative 'code'
|
|
7
7
|
require_relative 'code_blocks'
|
|
@@ -55,9 +55,9 @@ module Raindown
|
|
|
55
55
|
# Antlers strips the whitespace around a template, which can be Markdown, like an indented code block.
|
|
56
56
|
leading = template[/\A\s*/]
|
|
57
57
|
trailing = template[/\s*\z/]
|
|
58
|
-
# Write-in nodes and endpoints render here too, where loop variables are in scope, and
|
|
59
|
-
# fragments.
|
|
60
|
-
elements = Antlers::Elements[:html, :var, :if, :for] +
|
|
58
|
+
# Write-in nodes and endpoints, when the edition has them, render here too, where loop variables are in scope, and
|
|
59
|
+
# keep their HTML as fragments.
|
|
60
|
+
elements = Antlers::Elements[:html, :var, :if, :for] + Raindown.edition.elements
|
|
61
61
|
rendered = Antlers.render(ast: Antlers.ast(template:, elements:), current_binding: variables.binding, context:)
|
|
62
62
|
|
|
63
63
|
"#{leading}#{rendered}#{trailing}"
|
data/lib/raindown/projects.rb
CHANGED
|
@@ -11,8 +11,6 @@ module Raindown
|
|
|
11
11
|
module Projects
|
|
12
12
|
# Folders of dependencies, builds and tooling, which aren't searched for projects or watched, nor are hidden folders.
|
|
13
13
|
IGNORED = %w[node_modules vendor tmp pkg build dist coverage].freeze
|
|
14
|
-
# Ruby nodes and JavaScript Components.
|
|
15
|
-
NODE_EXTENSIONS = ['.rb', '.rbx', *JSNodes::EXTENSIONS].freeze
|
|
16
14
|
VAULT_FOLDER = '.obsidian'
|
|
17
15
|
|
|
18
16
|
module_function
|
|
@@ -82,8 +80,10 @@ module Raindown
|
|
|
82
80
|
|
|
83
81
|
# Whether a file is one of a project's own nodes, which load when its watcher starts.
|
|
84
82
|
def node?(path, root:)
|
|
83
|
+
require_relative 'js/js_nodes'
|
|
84
|
+
require_relative 'markdown_nodes'
|
|
85
85
|
File.expand_path(path).start_with?(File.join(root, Nodes::FOLDER, '')) &&
|
|
86
|
-
(
|
|
86
|
+
(['.rb', '.rbx', *JSNodes::EXTENSIONS].include?(File.extname(path)) || MarkdownNodes.file?(path))
|
|
87
87
|
end
|
|
88
88
|
|
|
89
89
|
# The roots that aren't inside another of them, as a project's code includes the projects inside it.
|
data/lib/raindown/rasters.rb
CHANGED
data/lib/raindown/rewriter.rb
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative 'node_injector'
|
|
4
|
-
require_relative 'endpoint/endpoint_runner'
|
|
5
|
-
require_relative 'table/table_formatter'
|
|
6
4
|
require_relative 'utils'
|
|
7
5
|
|
|
8
6
|
module Raindown
|
|
@@ -24,10 +22,13 @@ module Raindown
|
|
|
24
22
|
injected = injector.call
|
|
25
23
|
# Only a file naming an endpoint has one to run, so the rest aren't read again for one.
|
|
26
24
|
if injected.include?('endpoint:')
|
|
27
|
-
|
|
25
|
+
runner = Raindown.edition.plugs(:endpoint_runner).first
|
|
26
|
+
endpoints = runner&.new(content: injected, path:, bare: BareDirectives.enabled?(path:, content: injected, bare:), execute:)
|
|
28
27
|
end
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
lined_up = Raindown.edition.plugs(:table_formatter).reduce(endpoints&.rewrite || injected) do |text, formatter|
|
|
29
|
+
formatter.rewrite(content: text)
|
|
30
|
+
end
|
|
31
|
+
Rewrite.new(original: content, content: lined_up, failures: Array(endpoints&.failures), problems: injector.problems)
|
|
31
32
|
end
|
|
32
33
|
|
|
33
34
|
# Writes the file only when it changed.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Raindown
|
|
4
|
+
# A project's nodes in Ruby, in its .raindown folder, loaded with Dirload, which define LowNodes as constants.
|
|
5
|
+
module RubyNodes
|
|
6
|
+
module_function
|
|
7
|
+
|
|
8
|
+
# Dirload's steps, for the folder's Ruby files, as dirload(folder) takes them, a file that fails one being left out
|
|
9
|
+
# of the next, and why each failed.
|
|
10
|
+
def load(folder)
|
|
11
|
+
require 'lownode'
|
|
12
|
+
require 'dirload'
|
|
13
|
+
files = Dirload.file_paths(absolute_path: folder).map { [it, Dirload.find_adapter(file_path: it)] }
|
|
14
|
+
errors = {}
|
|
15
|
+
%i[mapload preload evaluate].each do |step|
|
|
16
|
+
files.each do |file, adapter|
|
|
17
|
+
next if adapter.nil? || errors.key?(file)
|
|
18
|
+
|
|
19
|
+
adapter.public_send(step, file_path: file)
|
|
20
|
+
rescue StandardError, ScriptError => e
|
|
21
|
+
errors[file] = e.message
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
errors.map { |file, message| load_error(folder, file, message) }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Why a file couldn't be loaded, by its path from the project, with its line, when the error has it.
|
|
28
|
+
def load_error(folder, file, message)
|
|
29
|
+
listed = file.delete_prefix("#{File.dirname(folder)}/")
|
|
30
|
+
return "#{listed}#{message.delete_prefix(file)}" if message.start_with?("#{file}:")
|
|
31
|
+
|
|
32
|
+
"#{listed}: #{message}"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def node_class(name)
|
|
36
|
+
klass = Object.const_get(name) if name.match?(/\A[A-Z]/) && Object.const_defined?(name)
|
|
37
|
+
klass if Nodes.node?(klass)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# FileUtils makes a new file's folders. It's loaded with a table:, rather than when one's made, so the Obsidian plugin's
|
|
4
|
+
# trace, which writes back tables but needn't make one, packs it.
|
|
5
|
+
require 'fileutils'
|
|
6
|
+
|
|
3
7
|
# Loaded when first used, as it loads strscan, a native extension, which slows a packed executable's start.
|
|
4
8
|
autoload :CSV, 'csv'
|
|
5
9
|
|
data/lib/raindown.rb
CHANGED
|
@@ -11,7 +11,6 @@ module Unicode
|
|
|
11
11
|
autoload :DisplayWidth, 'unicode/display_width'
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
require_relative 'elements'
|
|
15
14
|
require_relative 'raindown/bare_directives'
|
|
16
15
|
require_relative 'raindown/code'
|
|
17
16
|
require_relative 'raindown/config'
|
|
@@ -24,7 +23,6 @@ require_relative 'raindown/node_blocks'
|
|
|
24
23
|
require_relative 'raindown/outdent'
|
|
25
24
|
require_relative 'raindown/pages/pages'
|
|
26
25
|
require_relative 'raindown/pre_renderer'
|
|
27
|
-
require_relative 'raindown/table/table_formatter'
|
|
28
26
|
require_relative 'raindown/utils'
|
|
29
27
|
require_relative 'raindown/variables'
|
|
30
28
|
require_relative 'raindown/wiki_links'
|
|
@@ -116,6 +114,7 @@ module Raindown
|
|
|
116
114
|
def commonmark(markdown)
|
|
117
115
|
return markdown unless commonmark?
|
|
118
116
|
|
|
117
|
+
require_relative 'raindown/table/table_formatter'
|
|
119
118
|
doc = parse_markdown(hide_directives(markdown: TableFormatter.gfm(markdown)))
|
|
120
119
|
preserve_code(doc:)
|
|
121
120
|
|
data/lib/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: raindown
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.25.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- maedi
|
|
@@ -202,7 +202,6 @@ extensions: []
|
|
|
202
202
|
extra_rdoc_files: []
|
|
203
203
|
files:
|
|
204
204
|
- bin/raindown
|
|
205
|
-
- lib/elements.rb
|
|
206
205
|
- lib/lexemes/endpoint_lexeme.rb
|
|
207
206
|
- lib/lexemes/node_lexeme.rb
|
|
208
207
|
- lib/nodes/endpoint_node.rb
|
|
@@ -229,6 +228,7 @@ files:
|
|
|
229
228
|
- lib/raindown/directives.rb
|
|
230
229
|
- lib/raindown/document.rb
|
|
231
230
|
- lib/raindown/editing.rb
|
|
231
|
+
- lib/raindown/edition.rb
|
|
232
232
|
- lib/raindown/endpoint/curl.rb
|
|
233
233
|
- lib/raindown/endpoint/curl_request.rb
|
|
234
234
|
- lib/raindown/endpoint/curl_response.rb
|
|
@@ -236,6 +236,7 @@ files:
|
|
|
236
236
|
- lib/raindown/endpoint/endpoint_runner.rb
|
|
237
237
|
- lib/raindown/endpoint/endpoint_variables.rb
|
|
238
238
|
- lib/raindown/endpoint/schema_block.rb
|
|
239
|
+
- lib/raindown/features.rb
|
|
239
240
|
- lib/raindown/fragments.rb
|
|
240
241
|
- lib/raindown/front_matter.rb
|
|
241
242
|
- lib/raindown/gitignore.rb
|
|
@@ -270,6 +271,7 @@ files:
|
|
|
270
271
|
- lib/raindown/projects.rb
|
|
271
272
|
- lib/raindown/rasters.rb
|
|
272
273
|
- lib/raindown/rewriter.rb
|
|
274
|
+
- lib/raindown/ruby_nodes.rb
|
|
273
275
|
- lib/raindown/scene.rb
|
|
274
276
|
- lib/raindown/server.rb
|
|
275
277
|
- lib/raindown/services.rb
|
data/lib/elements.rb
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'plugs'
|
|
4
|
-
|
|
5
|
-
module Raindown
|
|
6
|
-
class Elements
|
|
7
|
-
include Plugs
|
|
8
|
-
|
|
9
|
-
# Write-in nodes, in <{ }>, like <{ Card }>, <{ :toc }> or <{ Card: }>...<{ :Card }>, rendered in the template pass.
|
|
10
|
-
plug(:write_in) do
|
|
11
|
-
plug(:lexeme) do
|
|
12
|
-
require_relative 'lexemes/node_lexeme'
|
|
13
|
-
NodeLexeme
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
# A list: block loops over its files, so it comes before other nodes' blocks.
|
|
17
|
-
plug(:node) do
|
|
18
|
-
require_relative 'nodes/list_node'
|
|
19
|
-
ListNode
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
plug(:node) do
|
|
23
|
-
require_relative 'nodes/write_in_node'
|
|
24
|
-
WriteInNode
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
plug(:node) do
|
|
28
|
-
require_relative 'nodes/write_in_node'
|
|
29
|
-
SoloWriteInNode
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
plug(:endpoint) do
|
|
34
|
-
plug(:lexeme) do
|
|
35
|
-
require_relative 'lexemes/endpoint_lexeme'
|
|
36
|
-
EndpointLexeme
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
plug(:node) do
|
|
40
|
-
require_relative 'nodes/endpoint_node'
|
|
41
|
-
EndpointNode
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|