You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-08-10 22:11:50 +02:00
Chore: Improve OneNote converter debugging (#12359)
This commit is contained in:
1
packages/onenote-converter/Cargo.lock
generated
1
packages/onenote-converter/Cargo.lock
generated
@@ -437,6 +437,7 @@ dependencies = [
|
||||
"encoding_rs",
|
||||
"enum-primitive-derive",
|
||||
"itertools",
|
||||
"lazy_static",
|
||||
"log",
|
||||
"mime_guess",
|
||||
"num-traits",
|
||||
|
@@ -30,6 +30,7 @@ thiserror = "1.0"
|
||||
uuid = "1.1.2"
|
||||
widestring = "1.0.2"
|
||||
wasm-bindgen = "0.2"
|
||||
lazy_static = "1.4"
|
||||
|
||||
[dependencies.web-sys]
|
||||
version = "0.3"
|
||||
|
@@ -27,6 +27,7 @@ pub(crate) mod section;
|
||||
pub(crate) mod table;
|
||||
|
||||
extern crate console_error_panic_hook;
|
||||
extern crate lazy_static;
|
||||
|
||||
/// The OneNote file parser.
|
||||
pub struct Parser;
|
||||
|
@@ -5,6 +5,7 @@ use crate::parser::one::property_set::{page_manifest_node, page_metadata, page_n
|
||||
use crate::parser::onenote::outline::{parse_outline, Outline};
|
||||
use crate::parser::onenote::page_content::{parse_page_content, PageContent};
|
||||
use crate::parser::onestore::object_space::ObjectSpace;
|
||||
use crate::utils::set_current_page;
|
||||
|
||||
/// A page.
|
||||
///
|
||||
@@ -189,6 +190,10 @@ pub(crate) fn parse_page(page_space: &ObjectSpace) -> Result<Page> {
|
||||
.title
|
||||
.map(|id| parse_title(id, page_space))
|
||||
.transpose()?;
|
||||
|
||||
let page_title = extract_text_from_title(&title);
|
||||
set_current_page(page_title);
|
||||
|
||||
let level = metadata.page_level;
|
||||
|
||||
let contents = data
|
||||
@@ -256,3 +261,21 @@ fn parse_metadata(space: &ObjectSpace) -> Result<page_metadata::Data> {
|
||||
|
||||
page_metadata::parse(metadata_object)
|
||||
}
|
||||
|
||||
fn extract_text_from_title(title: &Option<Title>) -> String {
|
||||
let mut result = String::new();
|
||||
if let Some(title_content) = title {
|
||||
for outline in &title_content.contents {
|
||||
for item in &outline.items {
|
||||
if let Some(element) = item.element() {
|
||||
for content in &element.contents {
|
||||
if let Some(rich_text) = content.rich_text() {
|
||||
result.push_str(&rich_text.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
|
@@ -1,8 +1,10 @@
|
||||
use crate::parser::errors::Result;
|
||||
use itertools::Itertools;
|
||||
use lazy_static::lazy_static;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
use std::fmt::Display;
|
||||
use std::sync::Mutex;
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
use wasm_bindgen::JsValue;
|
||||
use widestring::U16CString;
|
||||
@@ -138,6 +140,9 @@ pub mod utils {
|
||||
|
||||
macro_rules! log_warn {
|
||||
( $( $t:tt )* ) => {
|
||||
use crate::utils::get_current_page;
|
||||
|
||||
web_sys::console::warn_1(&format!("OneNoteConverter: Warning around the following page: {}", get_current_page().unwrap()).into());
|
||||
web_sys::console::warn_2(&format!("OneNoteConverter: ").into(), &format!( $( $t )* ).into());
|
||||
}
|
||||
}
|
||||
@@ -162,3 +167,17 @@ impl Utf16ToString for &[u8] {
|
||||
Ok(value.to_string().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref CURRENT_PAGE: Mutex<Option<String>> = Mutex::new(None);
|
||||
}
|
||||
|
||||
pub fn set_current_page(page_name: String) {
|
||||
let mut current_page = CURRENT_PAGE.lock().unwrap();
|
||||
*current_page = Some(page_name.to_string());
|
||||
}
|
||||
|
||||
pub fn get_current_page() -> Option<String> {
|
||||
let current_page = CURRENT_PAGE.lock().unwrap();
|
||||
current_page.clone()
|
||||
}
|
||||
|
Reference in New Issue
Block a user