use super::super::page_info::PageInfo;
use super::super::parsing::SyntaxTree;
use super::super::prelude::*;
use super::super::settings::WikitextSettings;
use crate::render::Render;
use crate::render::html::{HtmlOutput as RustHtmlOutput, HtmlRender};
use std::sync::Arc;
#[wasm_bindgen(typescript_custom_section)]
const TS_APPEND_CONTENT: &str = r#"
export interface IHtmlOutput {
body: string;
style: string;
meta: IHtmlMeta[];
}
export interface IHtmlMeta {
tag_type: string;
name: string;
value: string;
}
export interface IBacklinks {
included_pages: string[];
internal_links: string[];
external_links: string[];
}
"#;
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(typescript_type = "string[]")]
pub type IStyleArray;
#[wasm_bindgen(typescript_type = "IHtmlMeta[]")]
pub type IHtmlMetaArray;
#[wasm_bindgen(typescript_type = "IBacklinks")]
pub type IBacklinks;
}
#[wasm_bindgen]
#[derive(Debug, Clone)]
pub struct HtmlOutput {
inner: Arc<RustHtmlOutput>,
}
#[wasm_bindgen]
impl HtmlOutput {
#[wasm_bindgen]
pub fn copy(&self) -> HtmlOutput {
HtmlOutput {
inner: Arc::clone(&self.inner),
}
}
#[wasm_bindgen]
pub fn body(&self) -> String {
self.inner.body.clone()
}
#[wasm_bindgen]
pub fn html_meta(&self) -> Result<IHtmlMetaArray, JsValue> {
rust_to_js!(self.inner.meta).map(|meta| meta.into())
}
#[wasm_bindgen]
pub fn backlinks(&self) -> Result<IBacklinks, JsValue> {
rust_to_js!(self.inner.backlinks).map(|backlinks| backlinks.into())
}
}
#[wasm_bindgen]
pub fn render_html(
syntax_tree: SyntaxTree,
page_info: PageInfo,
settings: WikitextSettings,
) -> HtmlOutput {
let tree = syntax_tree.get();
let page_info = page_info.get();
let settings = settings.get();
let html = HtmlRender.render(tree, page_info, settings);
HtmlOutput {
inner: Arc::new(html),
}
}