Last active
August 29, 2015 13:57
-
-
Save skoji/9476487 to your computer and use it in GitHub Desktop.
NoraMark (http://github.com/skoji/noramark) customization sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
text =<<EOF | |
speak(Alice): Alice is speaking. | |
speak(Bob): and this is Bob. | |
EOF | |
document = NoraMark::Document.parse(text) | |
document.add_transformer(generator: :html) do | |
modify "speak" do | |
@node.name = 'p' | |
@node.prepend_child inline('span', @node.parameters[0], classes: ['speaker']) | |
end | |
end | |
puts document.html[0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> | |
<head> | |
<title>NoraMark generated document</title> | |
</head> | |
<body> | |
<p><span class='speaker'>Alice</span>Alice is speaking.</p> | |
<p><span class='speaker'>Bob</span>and this is Bob.</p> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
text = <<EOF | |
--- | |
lang: ja | |
--- | |
=: 見出し | |
パラグラフ。 | |
パラグラフ。 | |
EOF | |
document = NoraMark::Document.parse(text) | |
document.add_transformer(generator: :html) do | |
replace({:type => :HeadedSection}) do # 引数はNodeセレクタ | |
# この中では@nodeで処理対象のNodeにアクセスできる | |
# block() はBlock Nodeを生成するメソッド。inline()もある。他のNodeも直接Newすることは可能だが通常は不要 | |
header = block('header', | |
block('div', | |
block("h#{@node.level}", @node.heading), | |
classes: ['hgroup'])) | |
body = block('div', @node.children, classes:['section-body']) | |
block('section', [ header, body ], template: @node) # 操作が:replaceの場合は、このブロックが返すNodeで元のNodeが置き換えられる | |
end | |
end | |
document.html[0] # output follows |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja"> | |
<head> | |
<title>NoraMark generated document</title> | |
</head> | |
<body> | |
<section><header><div class='hgroup'><h1 id='heading_index_1'>見出し</h1> | |
</div> | |
</header> | |
<div class='section-body'><div class='pgroup'><p>パラグラフ。</p> | |
<p>パラグラフ。</p> | |
</div> | |
</div> | |
</section> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment