raindown 0.23.0 → 0.24.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/code.rb +4 -1
- data/lib/raindown/edition.rb +33 -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/nodes.rb +17 -7
- data/lib/raindown/rewriter.rb +2 -0
- data/lib/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0f3b834e7a8b9d814671cf9933f6098c256506d62b9732c56f0b9fa6f7c551fc
|
|
4
|
+
data.tar.gz: b6774b87bf5aac5d9b3441132b317471cfaf5f2d86c016161440cd067c8916ee
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5d4b2140306944e1a4e3594c0e2d08ae21c347aea5b774975019899b66108bd998814690dafd80fe29d7ecec46c378272e549d166d4c86376085de7d073bff22
|
|
7
|
+
data.tar.gz: d89db7996b541065249cd15f948c16e6827024bfa3cf38db49f9bbddb9a1648895077d261156e69a6e0b237784e1471d830a44ec36aca4e528811fa873187441
|
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.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Raindown
|
|
4
|
+
# What a product built on Raindown does with it, set before any note's written: Raindown itself, with its own nodes,
|
|
5
|
+
# like toc: and table:, endpoints, tables lined up, and a project's Ruby, JavaScript and Markdown Components in its
|
|
6
|
+
# .raindown folder, or Components, the Obsidian plugin for beginners, with only Markdown Components, in a vault's
|
|
7
|
+
# Components folder, which Obsidian shows, and nothing else, so the rest of a note, like a table, stays as it's
|
|
8
|
+
# written.
|
|
9
|
+
class Edition
|
|
10
|
+
attr_reader :folder
|
|
11
|
+
|
|
12
|
+
def initialize(folder:, full:)
|
|
13
|
+
@folder = folder
|
|
14
|
+
@full = full
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Whether it has Raindown's own nodes, endpoints, tables lined up, and Ruby and JavaScript Components.
|
|
18
|
+
def full?
|
|
19
|
+
@full
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
FULL = new(folder: '.raindown', full: true)
|
|
23
|
+
COMPONENTS = new(folder: 'Components', full: false)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
class << self
|
|
27
|
+
attr_writer :edition
|
|
28
|
+
|
|
29
|
+
def edition
|
|
30
|
+
@edition ||= Edition::FULL
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
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)
|
data/lib/raindown/nodes.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative 'edition'
|
|
3
4
|
require_relative 'fragments'
|
|
4
5
|
require_relative 'js/js_nodes'
|
|
5
6
|
require_relative 'markdown_nodes'
|
|
@@ -35,16 +36,25 @@ module Raindown
|
|
|
35
36
|
|
|
36
37
|
module_function
|
|
37
38
|
|
|
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.
|
|
39
|
+
# Loads the .raindown folder beside the file or in the nearest directory above it, or the edition's own, like
|
|
40
|
+
# Components', once per process, and gives why any of its files couldn't be loaded, like ".raindown/stars.rb:3:
|
|
41
|
+
# syntax errors found". Each file loads on its own, so one that can't be leaves the others loaded. An edition that
|
|
42
|
+
# isn't full only has Markdown Components.
|
|
41
43
|
def load(path)
|
|
42
44
|
folder = find_folder(File.dirname(File.expand_path(path)))
|
|
43
45
|
return [] if folder.nil?
|
|
44
46
|
return load_errors[folder] if loaded.include?(folder)
|
|
45
47
|
|
|
46
48
|
loaded << folder
|
|
47
|
-
load_errors[folder] =
|
|
49
|
+
load_errors[folder] = load_folder(folder)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# The folder's components loaded, with why any couldn't be: only its Markdown Components in an edition that isn't
|
|
53
|
+
# full.
|
|
54
|
+
def load_folder(folder)
|
|
55
|
+
return MarkdownNodes.load(folder) unless Raindown.edition.full?
|
|
56
|
+
|
|
57
|
+
load_ruby(folder) + JSNodes.load(folder) + MarkdownNodes.load(folder)
|
|
48
58
|
end
|
|
49
59
|
|
|
50
60
|
# Dirload's steps, for the folder's Ruby files, as dirload(folder) takes them, a file that fails one being left out
|
|
@@ -80,7 +90,7 @@ module Raindown
|
|
|
80
90
|
|
|
81
91
|
def find_folder(directory)
|
|
82
92
|
loop do
|
|
83
|
-
folder = File.join(directory,
|
|
93
|
+
folder = File.join(directory, Raindown.edition.folder)
|
|
84
94
|
return folder if File.directory?(folder)
|
|
85
95
|
|
|
86
96
|
parent = File.dirname(directory)
|
|
@@ -94,9 +104,9 @@ module Raindown
|
|
|
94
104
|
@loaded ||= []
|
|
95
105
|
end
|
|
96
106
|
|
|
97
|
-
# The node class a block names, when it's loaded.
|
|
107
|
+
# The node class a block names, when it's loaded, and Raindown's own, in a full edition.
|
|
98
108
|
def node_class(name)
|
|
99
|
-
return loaded_class(name) unless BUILT_INS.key?(name)
|
|
109
|
+
return loaded_class(name) unless BUILT_INS.key?(name) && Raindown.edition.full?
|
|
100
110
|
|
|
101
111
|
loaded_class(BUILT_INS[name]) || Raindown.const_get(BUILT_INS[name])
|
|
102
112
|
end
|
data/lib/raindown/rewriter.rb
CHANGED
|
@@ -22,6 +22,8 @@ module Raindown
|
|
|
22
22
|
def rewrite(content:, path:, bare: false, execute: false, metadata: NoMetadata)
|
|
23
23
|
injector = NodeInjector.new(content:, path:, bare:, metadata:)
|
|
24
24
|
injected = injector.call
|
|
25
|
+
return Rewrite.new(original: content, content: injected, failures: [], problems: injector.problems) unless Raindown.edition.full?
|
|
26
|
+
|
|
25
27
|
# Only a file naming an endpoint has one to run, so the rest aren't read again for one.
|
|
26
28
|
if injected.include?('endpoint:')
|
|
27
29
|
endpoints = EndpointRunner.new(content: injected, path:, bare: BareDirectives.enabled?(path:, content: injected, bare:), execute:)
|
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.24.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- maedi
|
|
@@ -229,6 +229,7 @@ files:
|
|
|
229
229
|
- lib/raindown/directives.rb
|
|
230
230
|
- lib/raindown/document.rb
|
|
231
231
|
- lib/raindown/editing.rb
|
|
232
|
+
- lib/raindown/edition.rb
|
|
232
233
|
- lib/raindown/endpoint/curl.rb
|
|
233
234
|
- lib/raindown/endpoint/curl_request.rb
|
|
234
235
|
- lib/raindown/endpoint/curl_response.rb
|