hierogloss 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -2
- data/bin/hierogloss +8 -2
- data/examples/disjunction.md +1 -1
- data/examples/disjunction.png +0 -0
- data/lib/hierogloss/gloss.rb +19 -15
- data/lib/hierogloss/mdc.rb +43 -12
- data/lib/hierogloss/version.rb +1 -1
- data/lib/kramdown/parser/hierogloss.rb +2 -1
- data/test/test_gloss.rb +4 -0
- data/test/test_mdc.rb +15 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2217a6d05d499f86580c6cab5f2125b6d2a2be61
|
4
|
+
data.tar.gz: 1271a83c6216b0e156e4d0db70d7cff4161b5501
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00e1516a717baec63b0b0b7f41916cd3082d3300db386123bdc79e622813fb316050de6cd43b642e356a6bd3f90b405fbfc17f7ac182d8b2c37235124d20c1ba
|
7
|
+
data.tar.gz: ba57a23e71dc632fe92fc63960270cda4d1dc555107a30c6e381e17ed2b38d5de40825fab1e3463b1df72c618c87bc5afc381f97f956c2f3601ce61d052fe8a3
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ write:
|
|
12
12
|
This example is based on one in Allen's excellent [Middle Egyptian: An
|
13
13
|
Introduction to the Language and Culture of Hieroglyphs][allen].
|
14
14
|
|
15
|
-
H: z:A1*Z1 | 𓊃:𓏏*𓁐 |
|
15
|
+
H: z:A1*Z1 | 𓊃:𓏏*𓁐 | 𓂋:𓏤-𓊪𓅱
|
16
16
|
L: s | s.t | r-pw
|
17
17
|
G: man | woman | whichever
|
18
18
|
T: either [a] man or [a] woman
|
@@ -27,8 +27,9 @@ be presented in an appropriate font with Unicode characters.
|
|
27
27
|
|
28
28
|
You can render this as HTML by running:
|
29
29
|
|
30
|
-
hierogloss example.md > example.html
|
30
|
+
hierogloss -i example.md > example.html
|
31
31
|
|
32
|
+
The `-i` flag causes `hierogloss` to render the hieroglyphs as images.
|
32
33
|
This will give you the following:
|
33
34
|
|
34
35
|
> ![](examples/disjunction.png)
|
data/bin/hierogloss
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'optparse'
|
4
4
|
require 'hierogloss'
|
5
5
|
|
6
|
-
options = { format: 'html' }
|
6
|
+
options = { format: 'html', images: false }
|
7
7
|
|
8
8
|
OptionParser.new do |opts|
|
9
9
|
opts.banner = "Usage: hierogloss [options] files..."
|
@@ -13,9 +13,15 @@ OptionParser.new do |opts|
|
|
13
13
|
" (defaults to html)") do |format|
|
14
14
|
options[:format] = format
|
15
15
|
end
|
16
|
+
|
17
|
+
opts.on("-i", "--[no-]images",
|
18
|
+
"Use inline images to render hieroglyphs",
|
19
|
+
" (defaults to off)") do |images|
|
20
|
+
options[:images] = images
|
21
|
+
end
|
16
22
|
end.parse!
|
17
23
|
|
18
|
-
args = { input: 'hierogloss' }
|
24
|
+
args = { input: 'hierogloss', use_images_for_signs: options[:images] }
|
19
25
|
if options[:format] == 'html'
|
20
26
|
args[:template] =
|
21
27
|
File.join(File.dirname(__FILE__), '..', 'data', 'hierogloss.html.erb')
|
data/examples/disjunction.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
This example is based on one in Allen's excellent [Middle Egyptian: An
|
4
4
|
Introduction to the Language and Culture of Hieroglyphs][allen].
|
5
5
|
|
6
|
-
H: z:A1*Z1 | 𓊃:𓏏*𓁐 |
|
6
|
+
H: z:A1*Z1 | 𓊃:𓏏*𓁐 | 𓂋:𓏤-𓊪𓅱
|
7
7
|
L: s | s.t | r-pw
|
8
8
|
G: man | woman | whichever
|
9
9
|
T: either [a] man or [a] woman
|
data/examples/disjunction.png
CHANGED
Binary file
|
data/lib/hierogloss/gloss.rb
CHANGED
@@ -27,12 +27,12 @@ module Hierogloss
|
|
27
27
|
nil
|
28
28
|
end
|
29
29
|
|
30
|
-
def to_kramdown
|
30
|
+
def to_kramdown(options)
|
31
31
|
attrs = attributes
|
32
32
|
tr = Kramdown::Element.new(:tr, nil, attrs)
|
33
33
|
cells.each do |c|
|
34
34
|
td = Kramdown::Element.new(:td)
|
35
|
-
children = cell_to_kramdown(c)
|
35
|
+
children = cell_to_kramdown(c, options)
|
36
36
|
if children.kind_of?(Array)
|
37
37
|
td.children.concat(children)
|
38
38
|
else
|
@@ -43,7 +43,7 @@ module Hierogloss
|
|
43
43
|
tr
|
44
44
|
end
|
45
45
|
|
46
|
-
def cell_to_kramdown(cell)
|
46
|
+
def cell_to_kramdown(cell, options)
|
47
47
|
Kramdown::Element.new(:text, cell)
|
48
48
|
end
|
49
49
|
|
@@ -71,13 +71,17 @@ module Hierogloss
|
|
71
71
|
@cells ||= raw_cells.map {|c| Hierogloss::MdC.parse(c) }
|
72
72
|
end
|
73
73
|
|
74
|
-
def cell_to_kramdown(cell)
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
74
|
+
def cell_to_kramdown(cell, options)
|
75
|
+
if options[:use_images_for_signs]
|
76
|
+
Kramdown::Element.new(:img, nil, 'src' => cell.to_mdc_image_url)
|
77
|
+
else
|
78
|
+
cell.to_linear_hieroglyphs.chars.map do |c|
|
79
|
+
gardiner = Dictionary.sign_to_gardiner(c)
|
80
|
+
unless gardiner.nil? || UNLINKED[c]
|
81
|
+
search_link("Signe:#{gardiner}", c)
|
82
|
+
else
|
83
|
+
Kramdown::Element.new(:text, c)
|
84
|
+
end
|
81
85
|
end
|
82
86
|
end
|
83
87
|
end
|
@@ -107,7 +111,7 @@ module Hierogloss
|
|
107
111
|
'hgls-l'
|
108
112
|
end
|
109
113
|
|
110
|
-
def cell_to_kramdown(cell)
|
114
|
+
def cell_to_kramdown(cell, options)
|
111
115
|
fancy = self.class.fancy(cell)
|
112
116
|
search_link(Dictionary.headword(cell), fancy)
|
113
117
|
end
|
@@ -129,7 +133,7 @@ module Hierogloss
|
|
129
133
|
'hgls-t'
|
130
134
|
end
|
131
135
|
|
132
|
-
def to_kramdown
|
136
|
+
def to_kramdown(options)
|
133
137
|
em = Kramdown::Element.new(:em, nil)
|
134
138
|
em.children << Kramdown::Element.new(:text, text)
|
135
139
|
em
|
@@ -155,7 +159,7 @@ module Hierogloss
|
|
155
159
|
end
|
156
160
|
end
|
157
161
|
|
158
|
-
def to_kramdown
|
162
|
+
def to_kramdown(options={})
|
159
163
|
result = []
|
160
164
|
# Neither Kramdown nor BBCode support rowspans, so we'll just cheat
|
161
165
|
# for now.
|
@@ -164,7 +168,7 @@ module Hierogloss
|
|
164
168
|
rows.each do |r|
|
165
169
|
class_attr = "hgls-gloss #{r.class_attr}"
|
166
170
|
p = Kramdown::Element.new(:p, nil, 'class' => class_attr)
|
167
|
-
p.children << r.to_kramdown
|
171
|
+
p.children << r.to_kramdown(options)
|
168
172
|
result << p
|
169
173
|
end
|
170
174
|
else
|
@@ -172,7 +176,7 @@ module Hierogloss
|
|
172
176
|
alignment: [])
|
173
177
|
tbody = Kramdown::Element.new(:tbody)
|
174
178
|
table.children << tbody
|
175
|
-
rows.each {|r| tbody.children << r.to_kramdown }
|
179
|
+
rows.each {|r| tbody.children << r.to_kramdown(options) }
|
176
180
|
result << table
|
177
181
|
end
|
178
182
|
end
|
data/lib/hierogloss/mdc.rb
CHANGED
@@ -4,6 +4,16 @@ module Hierogloss
|
|
4
4
|
#:nodoc: Our parser for the Manuel de Codage format.
|
5
5
|
module MdC
|
6
6
|
class Block
|
7
|
+
protected
|
8
|
+
|
9
|
+
# This whole precedence business may need more test cases further work.
|
10
|
+
def maybe_parens(current, context, str)
|
11
|
+
if current < context
|
12
|
+
"(#{str})"
|
13
|
+
else
|
14
|
+
str
|
15
|
+
end
|
16
|
+
end
|
7
17
|
end
|
8
18
|
|
9
19
|
class Sign < Block
|
@@ -33,6 +43,27 @@ module Hierogloss
|
|
33
43
|
end
|
34
44
|
end
|
35
45
|
|
46
|
+
class Composed < Block
|
47
|
+
attr_reader :base, :composed
|
48
|
+
|
49
|
+
def initialize(base, composed)
|
50
|
+
@base = base
|
51
|
+
@composed = composed
|
52
|
+
end
|
53
|
+
|
54
|
+
def to_debug
|
55
|
+
[:composed, base.to_debug, composed.to_debug]
|
56
|
+
end
|
57
|
+
|
58
|
+
def to_linear_hieroglyphs
|
59
|
+
[base.to_linear_hieroglyphs, composed.to_linear_hieroglyphs]
|
60
|
+
end
|
61
|
+
|
62
|
+
def to_mdc(precedence)
|
63
|
+
maybe_parens(3, precedence, "#{base.to_mdc(3)}&#{composed.to_mdc(3)}")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
36
67
|
class Group < Block
|
37
68
|
attr_reader :blocks
|
38
69
|
|
@@ -47,17 +78,6 @@ module Hierogloss
|
|
47
78
|
def to_linear_hieroglyphs
|
48
79
|
blocks.map {|b| b.to_linear_hieroglyphs }
|
49
80
|
end
|
50
|
-
|
51
|
-
protected
|
52
|
-
|
53
|
-
# This whole precedence business may need more test cases further work.
|
54
|
-
def maybe_parens(current, context, str)
|
55
|
-
if current < context
|
56
|
-
"(#{str})"
|
57
|
-
else
|
58
|
-
str
|
59
|
-
end
|
60
|
-
end
|
61
81
|
end
|
62
82
|
|
63
83
|
class Sequence < Group
|
@@ -85,6 +105,11 @@ module Hierogloss
|
|
85
105
|
def to_mdc
|
86
106
|
blocks.map {|b| b.to_mdc(0) }.join("-")
|
87
107
|
end
|
108
|
+
|
109
|
+
def to_mdc_image_url
|
110
|
+
esc = URI.escape(to_mdc, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
111
|
+
"http://i.hierogloss.net/mdc/#{esc}.png"
|
112
|
+
end
|
88
113
|
end
|
89
114
|
|
90
115
|
class Parser < Parslet::Parser
|
@@ -97,12 +122,15 @@ module Hierogloss
|
|
97
122
|
rule(:unicode_sign) { match('[\u{13000}-\u{1342F}]') }
|
98
123
|
rule(:sign) { (alpha_sign | unicode_sign).as(:sign) >> space? }
|
99
124
|
|
125
|
+
# Signs with special composition behavior, as per JSesh.
|
126
|
+
rule(:composed) { sign.as(:base) >> str('&') >> atomic.as(:composed) }
|
127
|
+
|
100
128
|
# Parenthesized blocks.
|
101
129
|
rule(:parens) { str('(') >> space? >> sequence >> str(')') >> space? }
|
102
130
|
|
103
131
|
# "Terminal" chunks in our expression grammar, which will match
|
104
132
|
# an actual, concrete symbol in the first position.
|
105
|
-
rule(:atomic) { sign | parens }
|
133
|
+
rule(:atomic) { composed | sign | parens }
|
106
134
|
|
107
135
|
# A list of items with separators between them.
|
108
136
|
def separated(item, separator)
|
@@ -132,6 +160,9 @@ module Hierogloss
|
|
132
160
|
|
133
161
|
rule(head: subtree(:head), rest: sequence(:rest)) { [head].concat(rest) }
|
134
162
|
rule(sign: simple(:sign)) { Sign.new(sign.to_s) }
|
163
|
+
rule(base: simple(:base), composed: simple(:composed)) do
|
164
|
+
Composed.new(base, composed)
|
165
|
+
end
|
135
166
|
rule(stack: subtree(:list)) {|d| lists_as(Stack, d[:list]) }
|
136
167
|
rule(juxtaposed: subtree(:list)) {|d| lists_as(Sequence, d[:list]) }
|
137
168
|
end
|
data/lib/hierogloss/version.rb
CHANGED
@@ -27,7 +27,8 @@ module Kramdown
|
|
27
27
|
def parse_gloss
|
28
28
|
start_line_number = @src.current_line_number
|
29
29
|
data = @src.scan(self.class::GLOSS_MATCH)
|
30
|
-
|
30
|
+
elems = ::Hierogloss::Gloss.new(data).to_kramdown(@options)
|
31
|
+
@tree.children.concat(elems)
|
31
32
|
true
|
32
33
|
end
|
33
34
|
|
data/test/test_gloss.rb
CHANGED
data/test/test_mdc.rb
CHANGED
@@ -29,6 +29,10 @@ class TestCodage < MiniTest::Test
|
|
29
29
|
assert_parse([[:stack, "𓇾", ["𓏤", "𓈇"]]], "𓇾:𓏤*𓈇")
|
30
30
|
end
|
31
31
|
|
32
|
+
def test_should_parse_composed_signs
|
33
|
+
assert_parse([[:composed, "𓅱", "𓏏"]], "𓅱&𓏏")
|
34
|
+
end
|
35
|
+
|
32
36
|
def test_should_honor_parens
|
33
37
|
assert_parse([[:stack, ["p", [:stack, "t", "Z4"]], "pt"]], "p*(t:Z4):pt")
|
34
38
|
end
|
@@ -40,6 +44,7 @@ class TestCodage < MiniTest::Test
|
|
40
44
|
def test_should_convert_mdc_to_linear_hieroglyphs
|
41
45
|
assert_linear_hieroglyphs("𓆓𓂧𓈖", "𓆓:𓂧𓈖")
|
42
46
|
assert_linear_hieroglyphs("𓊪𓏏𓏭𓇯", "p*(t:Z4):pt")
|
47
|
+
assert_linear_hieroglyphs("𓅱𓏏", "𓅱&𓏏")
|
43
48
|
end
|
44
49
|
|
45
50
|
def assert_mdc(expected, input)
|
@@ -49,7 +54,17 @@ class TestCodage < MiniTest::Test
|
|
49
54
|
def test_should_convert_mdc_to_mdc_string
|
50
55
|
assert_mdc("D:d-n", "𓆓:𓂧𓈖")
|
51
56
|
assert_mdc("p*(t:Z4):pt", "p*(t:Z4):pt")
|
57
|
+
assert_mdc("w&t", "𓅱&𓏏")
|
52
58
|
# Compound signs are always placed in parens.
|
53
59
|
assert_mdc("(N33*N33:N33*N33)", "𓃌")
|
54
60
|
end
|
61
|
+
|
62
|
+
def assert_mdc_image_url(expected, input)
|
63
|
+
assert_equal(expected, Hierogloss::MdC.parse(input).to_mdc_image_url)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_should_convert_to_mdc_image_url
|
67
|
+
assert_mdc_image_url("http://i.hierogloss.net/mdc/p*(t%3AZ4)%3Apt.png",
|
68
|
+
"p*(t:Z4):pt")
|
69
|
+
end
|
55
70
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hierogloss
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Kidd
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kramdown
|