Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/cmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ use docx_rs::Run;
use pulldown_cmark::Options;
use pulldown_cmark::{Event, Parser, Tag, TextMergeStream};

pub fn new_run_with_size() -> Run {
Run::new().size(constants::FONT_SIZE)
}

/// Parse a paragraph of a Markdown document into a list of Runs
pub fn parse_paragraph(input: &str) -> Vec<Run> {
let mut runs: Vec<Run> = vec![];
Expand All @@ -14,7 +18,7 @@ pub fn parse_paragraph(input: &str) -> Vec<Run> {
let parser = Parser::new_ext(input, options);
let iterator = TextMergeStream::new(parser);

let mut run = Run::new();
let mut run = new_run_with_size();
for event in iterator {
match event {
Event::Start(name) => {
Expand All @@ -26,15 +30,15 @@ pub fn parse_paragraph(input: &str) -> Vec<Run> {
// That's no longer the case with digital text, so we'll use italics instead.
// TODO: Make this configurable?
runs.push(run);
run = Run::new().italic();
run = new_run_with_size().italic();
}
Tag::Strong => {
runs.push(run);
run = Run::new().bold();
run = new_run_with_size().bold();
}
Tag::Strikethrough => {
runs.push(run);
run = Run::new().strike();
run = new_run_with_size().strike();
}
_ => {}
}
Expand All @@ -46,8 +50,8 @@ pub fn parse_paragraph(input: &str) -> Vec<Run> {
}
Event::End(_) => {
// We're at the end of a run, so save what we have and start the next one.
runs.push(run.size(constants::FONT_SIZE));
run = Run::new();
runs.push(run);
run = new_run_with_size();
}
_ => {}
}
Expand Down
Loading