summaryrefslogtreecommitdiffstats
path: root/src/generator/pandoc.rs
diff options
context:
space:
mode:
authorMinijackson <minijackson@riseup.net>2019-12-21 12:13:21 +0100
committerMinijackson <minijackson@riseup.net>2019-12-21 12:13:21 +0100
commite773caea8010b87726ea524d31798fb2e43e12f4 (patch)
tree9034295831afb25f4bfea5a05d9f83d03e69e86c /src/generator/pandoc.rs
parentde896baff7e97fac4dde79078c9a2fa1c652576b (diff)
downloadposeidoc-e773caea8010b87726ea524d31798fb2e43e12f4.tar.gz
poseidoc-e773caea8010b87726ea524d31798fb2e43e12f4.zip
newtype in types, more generator config, parsing -> parser
Diffstat (limited to 'src/generator/pandoc.rs')
-rw-r--r--src/generator/pandoc.rs19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/generator/pandoc.rs b/src/generator/pandoc.rs
index 1753d34..035acab 100644
--- a/src/generator/pandoc.rs
+++ b/src/generator/pandoc.rs
@@ -1,14 +1,11 @@
1use super::config::Config; 1use super::config::Config;
2use crate::types::Entity; 2use crate::types::*;
3 3
4use pandoc_types::definition::{Attr, Block, Inline, Meta, MetaValue, Pandoc}; 4use pandoc_types::definition::{Attr, Block, Inline, Meta, MetaValue, Pandoc};
5 5
6use std::collections::BTreeMap; 6use std::collections::BTreeMap;
7 7
8pub(crate) fn into_pandoc( 8pub(crate) fn into_pandoc(entity: Entity, config: &Config) -> (Pandoc, BTreeMap<EntityId, Entity>) {
9 entity: Entity,
10 config: &Config,
11) -> (Pandoc, BTreeMap<String, Entity>) {
12 let mut meta = Meta::null(); 9 let mut meta = Meta::null();
13 10
14 let title = vec![Inline::Code(Attr::null(), entity.name.clone())]; 11 let title = vec![Inline::Code(Attr::null(), entity.name.clone())];
@@ -57,7 +54,7 @@ pub(crate) fn into_pandoc(
57 content.push(Block::Header( 54 content.push(Block::Header(
58 2, 55 2,
59 Attr::null(), 56 Attr::null(),
60 vec![Inline::Str(String::from(section_name))], 57 vec![Inline::Str(section_name.0.clone())],
61 )); 58 ));
62 59
63 content.push(members_list); 60 content.push(members_list);
@@ -71,7 +68,7 @@ pub(crate) fn into_pandoc(
71 content.push(Block::Header( 68 content.push(Block::Header(
72 2, 69 2,
73 Attr::null(), 70 Attr::null(),
74 vec![Inline::Str(section_name.clone())], 71 vec![Inline::Str(section_name.0.clone())],
75 )); 72 ));
76 73
77 content.push(members_list); 74 content.push(members_list);
@@ -79,7 +76,7 @@ pub(crate) fn into_pandoc(
79 embedded_documentation.push(Block::Header( 76 embedded_documentation.push(Block::Header(
80 2, 77 2,
81 Attr::null(), 78 Attr::null(),
82 vec![Inline::Str(section_name + " Documentation")], 79 vec![Inline::Str(section_name.0 + " Documentation")],
83 )); 80 ));
84 81
85 for (_id, child) in children { 82 for (_id, child) in children {
@@ -112,7 +109,7 @@ fn str_block(content: String) -> Block {
112 Block::Plain(vec![Inline::Str(content)]) 109 Block::Plain(vec![Inline::Str(content)])
113} 110}
114 111
115fn entity_link(id: &str, name: String) -> Inline { 112fn entity_link(id: &EntityId, name: String) -> Inline {
116 use pandoc_types::definition::Target; 113 use pandoc_types::definition::Target;
117 use percent_encoding::{utf8_percent_encode, AsciiSet, CONTROLS}; 114 use percent_encoding::{utf8_percent_encode, AsciiSet, CONTROLS};
118 115
@@ -135,7 +132,7 @@ fn entity_link(id: &str, name: String) -> Inline {
135 vec![Inline::Code(Attr::null(), name)], 132 vec![Inline::Code(Attr::null(), name)],
136 Target( 133 Target(
137 once("./") 134 once("./")
138 .chain(utf8_percent_encode(id, FRAGMENT)) 135 .chain(utf8_percent_encode(&id.0, FRAGMENT))
139 .collect(), 136 .collect(),
140 String::new(), 137 String::new(),
141 ), 138 ),
@@ -147,7 +144,7 @@ fn raw_markdown(text: String) -> Block {
147 Block::RawBlock(Format(String::from("markdown")), text) 144 Block::RawBlock(Format(String::from("markdown")), text)
148} 145}
149 146
150fn member_list<'a>(members: impl IntoIterator<Item = (&'a String, &'a Entity)>) -> Option<Block> { 147fn member_list<'a>(members: impl IntoIterator<Item = (&'a EntityId, &'a Entity)>) -> Option<Block> {
151 let definitions: Vec<(Vec<Inline>, Vec<Vec<Block>>)> = members 148 let definitions: Vec<(Vec<Inline>, Vec<Vec<Block>>)> = members
152 .into_iter() 149 .into_iter()
153 .map(|(id, entity)| { 150 .map(|(id, entity)| {