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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c632614a09f0281efd217557eb046217430e45d0805dbfc33565383049081864
4
- data.tar.gz: '087a9634e4cd8f828fb67de10ea089af83ad8adbfe7bed374f5d08fab198af73'
3
+ metadata.gz: bd0f195f8b038fc719357e56ce0acf68bcb30b81053632e2241797adb8014b46
4
+ data.tar.gz: c897967b454ebf69c77a6298e78103765cb8d6bc4a0f40f6de7af83d60662d23
5
5
  SHA512:
6
- metadata.gz: a48b94bc9a805e8d694fa4454fc523bd227dcf488c9e2b8c77eb188757063f1403b22ad58029e0c4002caac68617f122aefa775da643d1b688f00d38fff306eb
7
- data.tar.gz: fb113d924d81571d524bbed1db73307a7d523953436c96bb76629f16d47259ae0461b11c80af84c843884337c4fcf8fe9cec55e33781e3e852bdd135a2a79324
6
+ metadata.gz: 6b140981b0a76c5f2ead4fd65dbcc6143865d5b5b6bd20239c2430189c86dfb1d293109cfe8265d8fbfd2aacdd93186c88bf6ebbfd467097bcde72e56e9d25d2
7
+ data.tar.gz: b90447ef75f5daa6799ea2a93fff1f4fc67f49147f944de08613f149c5ec7a1468fd7e226d5900e8921c57ac1ccfe53acba965b2d75ccb0df27b598023017752
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
- # Redel
1
+ # ReDel
2
2
 
3
- A **re**cursive **del**imiter parser for markup languages. It accepts any input: whatever
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
- Redel started as the parser of Didaktiki, the wiki of CEWebS, and was extracted from there.
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
- Redel::Simple.parse("some '''bold''' text").output(Redel::HTML.new)
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 < Redel::Grammar
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 < Redel::Output
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 `Redel::Markup`, or from `Redel::HTML` in order to
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 < Redel::HTML
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.
@@ -2,7 +2,7 @@ require 'open-uri'
2
2
  require_relative 'parser'
3
3
  require_relative 'xhtml'
4
4
 
5
- module Redel
5
+ module ReDel
6
6
  class Simple < Grammar
7
7
  #### Patterns ####
8
8
  #### Name of pattern has to be the first parameter to pattern ####
data/lib/redel/helpers.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  require 'markus'
3
3
  require 'cgi'
4
4
 
5
- module Redel
5
+ module ReDel
6
6
  # Additions for classes that inherit from MarkUS.
7
7
  #
8
8
  # String parameters (div_ "text") are escaped by markus. Markup has to be returned
data/lib/redel/image.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # Please see the LICENSE file for copyright and distribution information
2
2
  require 'open3'
3
3
 
4
- module Redel
4
+ module ReDel
5
5
  # ImageMagick, without needing a native gem
6
6
  module Image
7
7
  # [width,height] or nil if it is not an image
@@ -12,7 +12,7 @@ rescue LoadError
12
12
  # optional, formulas are shown as TeX source without it
13
13
  end
14
14
 
15
- module Redel
15
+ module ReDel
16
16
  # Base for outputs that create markup.
17
17
  #
18
18
  # There is one method per pattern: P_X(data) or P_X(data,node). It yields, where the
data/lib/redel/parser.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # Please see the LICENSE file for copyright and distribution information
2
2
  require 'strscan'
3
3
 
4
- module Redel
4
+ module ReDel
5
5
  class OpenTag
6
6
  attr_reader :type, :level
7
7
  attr_accessor :data, :close
data/lib/redel/xhtml.rb CHANGED
@@ -1,4 +1,4 @@
1
- module Redel; module XHTML
1
+ module ReDel; module XHTML
2
2
  def unweb(string) XHTML::unweb(string) end
3
3
  def web(string) XHTML::web(string) end
4
4
  def amp(string) XHTML::amp(string) end
data/redel.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "redel"
3
- s.version = "3.0.0"
3
+ s.version = "3.1.0"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.license = "GPL-3.0-or-later"
6
6
  s.summary = "Recursive delimiter parser for markup languages"
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) Redel::Simple.parse(text).output(Redel::HTML.new); end
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> &lt;c&gt; &#8594;&#160;</div>", simple("'''a''' ''b'' &lt;c&gt; -&gt;")
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 < Redel::Grammar
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 < Redel::Output
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>', Redel::Simple.parse("'''a''' ''b''").output(Text.new)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redel
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juergen eTM Mangler