Skip to content

Commit

Permalink
fix paragraph styles being applied to the wrong text runs
Browse files Browse the repository at this point in the history
  • Loading branch information
pedr committed Sep 4, 2024
1 parent ffd3358 commit 50c8697
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions packages/onenote-converter/src/page/rich_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use color_eyre::Result;
use itertools::Itertools;
use once_cell::sync::Lazy;
use regex::{Captures, Regex};
use crate::utils::utils::log_warn;

impl<'a> Renderer<'a> {
pub(crate) fn render_rich_text(&mut self, text: &RichText) -> Result<String> {
Expand Down Expand Up @@ -60,15 +61,29 @@ impl<'a> Renderer<'a> {
.join(""));
}

let indices = data.text_run_indices();
let styles = data.text_run_formatting();
let mut indices = data.text_run_indices().to_vec();
let mut styles = data.text_run_formatting().to_vec();

let mut text = data.text().to_string();

if text.is_empty() {
text = "&nbsp;".to_string();
}

// TODO: Maybe this shouldn't be here
// When the this character is at the start of the paragraph it makes
// all the styles to be shifted by minues one.
// A better solution would be to look if there isn't anything wrong with the parser,
// but I haven't found what could be causing this yet.
if text.starts_with("\u{000B}") && !indices.is_empty(){
indices.remove(0);
styles.pop();
}

This comment has been minimized.

Copy link
@laurent22

laurent22 Sep 4, 2024

Owner

Wouldn't we want a test for such a strange edge case?


if text.clone().contains("Action research involves") {
log_warn!("Hyperlink: {:?}, indices: {:?}, styles: {:?}", text, indices, styles);
}

if indices.is_empty() {
return Ok(fix_newlines(&text));
}
Expand Down

0 comments on commit 50c8697

Please sign in to comment.