Skip to content

Commit 20815c8

Browse files
committed
date:[] macro: #371
1 parent f122abd commit 20815c8

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

lib/metanorma/standoc/converter.rb

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Converter
2626
preprocessor Metanorma::Plugin::Datastruct::Json2TextPreprocessor
2727
preprocessor Metanorma::Plugin::Datastruct::Yaml2TextPreprocessor
2828
inline_macro Metanorma::Standoc::PreferredTermInlineMacro
29+
inline_macro Metanorma::Standoc::DateInlineMacro
2930
inline_macro Metanorma::Standoc::SpanInlineMacro
3031
inline_macro Metanorma::Standoc::AltTermInlineMacro
3132
inline_macro Metanorma::Standoc::AdmittedTermInlineMacro

lib/metanorma/standoc/isodoc.rng

+18
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,7 @@
10121012
<ref name="del"/>
10131013
<ref name="span"/>
10141014
<ref name="erefstack"/>
1015+
<ref name="date_inline"/>
10151016
</choice>
10161017
</define>
10171018
<define name="add">
@@ -1053,6 +1054,23 @@
10531054
</oneOrMore>
10541055
</element>
10551056
</define>
1057+
<define name="date_inline">
1058+
<element name="date">
1059+
<attribute name="value"/>
1060+
<optional>
1061+
<attribute name="format"/>
1062+
</optional>
1063+
<optional>
1064+
<attribute name="language"/>
1065+
</optional>
1066+
<optional>
1067+
<attribute name="script"/>
1068+
</optional>
1069+
<optional>
1070+
<attribute name="locale"/>
1071+
</optional>
1072+
</element>
1073+
</define>
10561074
<define name="concept">
10571075
<element name="concept">
10581076
<optional>

lib/metanorma/standoc/macros_inline.rb

+14-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def preprocess_attrs(attrs)
2727

2828
def process(_parent, target, attr)
2929
args = preprocess_attrs(attr) or return
30-
ret = "<index-xref also='#{target == 'also'}'>"\
30+
ret = "<index-xref also='#{target == 'also'}'>" \
3131
"<primary>#{args[:primary]}</primary>"
3232
ret += "<secondary>#{args[:secondary]}</secondary>" if args[:secondary]
3333
ret += "<tertiary>#{args[:tertiary]}</tertiary>" if args[:tertiary]
@@ -69,7 +69,7 @@ def process(_parent, target, attributes)
6969
rpend = attributes["rpend"]
7070
end
7171

72-
"<ruby>#{target}<rp>#{rpbegin}</rp><rt>#{rt}</rt>"\
72+
"<ruby>#{target}<rp>#{rpbegin}</rp><rt>#{rt}</rt>" \
7373
"<rp>#{rpend}</rp></ruby>"
7474
end
7575
end
@@ -101,6 +101,18 @@ def process(parent, target, attrs)
101101
end
102102
end
103103

104+
class DateInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
105+
use_dsl
106+
named :date
107+
using_format :short
108+
109+
def process(_parent, _target, attrs)
110+
format = "%F"
111+
attrs.size >= 2 and format = attrs[2]
112+
%{<date format='#{format}' value='#{attrs[1]}'/>}
113+
end
114+
end
115+
104116
class AddMacro < Asciidoctor::Extensions::InlineMacroProcessor
105117
use_dsl
106118
named :add

spec/metanorma/macros_spec.rb

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
add:[a <<clause>>] del:[B]
1515
identifier:[a http://example.com]
1616
span:category[text]
17+
date:[2012-03-04,%a-%b%s]
18+
date:[2012-03-04]
1719
1820
[bibliography]
1921
== Bibliography
@@ -40,6 +42,8 @@
4042
<del>B</del>
4143
<identifier>a http://example.com</identifier>
4244
<span class='category'>text</span>
45+
<date format="%a-%b%s" value="2012-03-04"/>
46+
<date format="%F" value="2012-03-04"/>
4347
</foreword>
4448
</preface>
4549
<sections> </sections>

0 commit comments

Comments
 (0)