redel 3.0.0 → 3.1.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/README.md +26 -8
- data/lib/redel/grammar_simple.rb +1 -1
- data/lib/redel/helpers.rb +1 -1
- data/lib/redel/image.rb +1 -1
- data/lib/redel/output_html.rb +1 -1
- data/lib/redel/parser.rb +1 -1
- data/lib/redel/xhtml.rb +1 -1
- data/redel.gemspec +1 -1
- data/test/tc_html.rb +1 -1
- data/test/tc_parser.rb +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bd0f195f8b038fc719357e56ce0acf68bcb30b81053632e2241797adb8014b46
|
|
4
|
+
data.tar.gz: c897967b454ebf69c77a6298e78103765cb8d6bc4a0f40f6de7af83d60662d23
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6b140981b0a76c5f2ead4fd65dbcc6143865d5b5b6bd20239c2430189c86dfb1d293109cfe8265d8fbfd2aacdd93186c88bf6ebbfd467097bcde72e56e9d25d2
|
|
7
|
+
data.tar.gz: b90447ef75f5daa6799ea2a93fff1f4fc67f49147f944de08613f149c5ec7a1468fd7e226d5900e8921c57ac1ccfe53acba965b2d75ccb0df27b598023017752
|
data/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ReDel
|
|
2
2
|
|
|
3
|
-
A **
|
|
3
|
+
A **Re**cursive **Del**imiter Parser for markup languages. It accepts any input: whatever
|
|
4
4
|
it does not recognize is plain text.
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
ReDel started as the parser of Didaktiki, the wiki of CEWebS, and was extracted from there.
|
|
7
7
|
Some traces are left, e.g. `CEWebS://` links in the simple grammar.
|
|
8
8
|
|
|
9
9
|
It contains a grammar for simple wiki texts (headings, lists, emphasis, links, code, ...), and
|
|
@@ -12,7 +12,7 @@ an output that creates HTML. The text has to be HTML-escaped (`&`, `<`, `>`, `"`
|
|
|
12
12
|
```ruby
|
|
13
13
|
require 'redel'
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
ReDel::Simple.parse("some '''bold''' text").output(ReDel::HTML.new)
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
Formulas are shown as TeX without the gem `itextomml`. Plots need `gle` and ImageMagick.
|
|
@@ -22,7 +22,7 @@ Formulas are shown as TeX without the gem `itextomml`. Plots need `gle` and Imag
|
|
|
22
22
|
```ruby
|
|
23
23
|
require 'redel'
|
|
24
24
|
|
|
25
|
-
class Language <
|
|
25
|
+
class Language < ReDel::Grammar
|
|
26
26
|
P_STRONG = Pattern.new('P_STRONG', /\*/, /\*/)
|
|
27
27
|
P_EM = Pattern.new('P_EM', /_/, /_/)
|
|
28
28
|
|
|
@@ -30,7 +30,7 @@ class Language < Redel::Grammar
|
|
|
30
30
|
GP_STRONG = [ P_EM ]
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
class Text <
|
|
33
|
+
class Text < ReDel::Output
|
|
34
34
|
def mOP_STRONG(data) '<b>'; end
|
|
35
35
|
def mCP_STRONG(data) '</b>'; end
|
|
36
36
|
def mOP_EM(data) '<i>'; end
|
|
@@ -57,16 +57,34 @@ Language.parse('some *bold _and italic_* text').output(Text.new)
|
|
|
57
57
|
* `mP` + name is called by `prepare`, for everything that has to be known before the output
|
|
58
58
|
starts: `Language.parse(text).prepare(output).output(output)`
|
|
59
59
|
* Outputs with a method `render` get the whole tree instead.
|
|
60
|
-
* For markup inherit from `
|
|
60
|
+
* For markup inherit from `ReDel::Markup`, or from `ReDel::HTML` in order to
|
|
61
61
|
change or extend it. There is one method per pattern, which uses
|
|
62
62
|
[markus](https://github.com/etm/markus) and yields for its content:
|
|
63
63
|
|
|
64
64
|
```ruby
|
|
65
|
-
class Mine <
|
|
65
|
+
class Mine < ReDel::HTML
|
|
66
66
|
def P_STRONG(data) b_(:class => 'mine') { yield }; end
|
|
67
67
|
end
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
+
## Why not a PEG parser?
|
|
71
|
+
|
|
72
|
+
Robustness. Wiki texts are written by people, and contain mistakes. A PEG describes valid
|
|
73
|
+
input: a text that does not match is a syntax error, unless the grammar has fallback rules
|
|
74
|
+
for everything that can go wrong.
|
|
75
|
+
|
|
76
|
+
ReDel needs no such rules. A start without an end is plain text, and as the end of a pattern
|
|
77
|
+
is searched before its content is parsed, a mistake inside of a pattern can not break the
|
|
78
|
+
pattern around it. With the language from above:
|
|
79
|
+
|
|
80
|
+
```ruby
|
|
81
|
+
Language.parse('*a _b* c_').output(Text.new)
|
|
82
|
+
# => <b>a _b</b> c_
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
The price: the first end wins, even if it is part of a nested pattern. For languages where
|
|
86
|
+
mistakes should be reported, e.g. programming languages, a PEG parser is the better choice.
|
|
87
|
+
|
|
70
88
|
## License
|
|
71
89
|
|
|
72
90
|
GPL-3.0-or-later, see LICENSE.
|
data/lib/redel/grammar_simple.rb
CHANGED
data/lib/redel/helpers.rb
CHANGED
data/lib/redel/image.rb
CHANGED
data/lib/redel/output_html.rb
CHANGED
data/lib/redel/parser.rb
CHANGED
data/lib/redel/xhtml.rb
CHANGED
data/redel.gemspec
CHANGED
data/test/tc_html.rb
CHANGED
|
@@ -2,7 +2,7 @@ require 'minitest/autorun'
|
|
|
2
2
|
require_relative '../lib/redel'
|
|
3
3
|
|
|
4
4
|
class TestHTML < Minitest::Test
|
|
5
|
-
def simple(text)
|
|
5
|
+
def simple(text) ReDel::Simple.parse(text).output(ReDel::HTML.new); end
|
|
6
6
|
|
|
7
7
|
def test_inline
|
|
8
8
|
assert_equal "<div><strong>a</strong> <em>b</em> <c> → </div>", simple("'''a''' ''b'' <c> ->")
|
data/test/tc_parser.rb
CHANGED
|
@@ -2,7 +2,7 @@ require 'minitest/autorun'
|
|
|
2
2
|
require_relative '../lib/redel'
|
|
3
3
|
|
|
4
4
|
class TestParser < Minitest::Test
|
|
5
|
-
class Language <
|
|
5
|
+
class Language < ReDel::Grammar
|
|
6
6
|
P_STRONG = Pattern.new('P_STRONG', /\*/, /\*/)
|
|
7
7
|
P_EM = Pattern.new('P_EM', /_/, /_/)
|
|
8
8
|
P_LINE = Pattern.new('P_LINE', /> /, /\n|\z/, true)
|
|
@@ -16,7 +16,7 @@ class TestParser < Minitest::Test
|
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
class Text <
|
|
19
|
+
class Text < ReDel::Output
|
|
20
20
|
attr_reader :lines
|
|
21
21
|
def mPP_LINE(data) (@lines ||= []) << data; end
|
|
22
22
|
def mOP_LINE(data) "<p #{data}>"; end
|
|
@@ -56,7 +56,7 @@ class TestParser < Minitest::Test
|
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
def test_simple
|
|
59
|
-
assert_equal '<b>a</b> <i>b</i>',
|
|
59
|
+
assert_equal '<b>a</b> <i>b</i>', ReDel::Simple.parse("'''a''' ''b''").output(Text.new)
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
def test_render
|