pub enum MarkupLanguage {
Markdown,
RestructuredText,
Html,
Txt,
Unknown,
None,
}Expand description
The Markup language of the note content.
Variants§
Markdown
RestructuredText
Html
Txt
Unknown
We can not determine the markup language, but confirm that this is a Tp-Note file.
None
This is not a Tp-Note file.
Implementations§
source§impl MarkupLanguage
impl MarkupLanguage
sourcepub fn or(self, rhs: Self) -> Self
pub fn or(self, rhs: Self) -> Self
If Self is None return rhs, otherwise return Self.
Examples found in repository?
src/note.rs (line 487)
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
pub fn render_content_to_html(
&self,
// We need the file extension to determine the
// markup language.
file_ext: &str,
// HTML template for this rendition.
tmpl: &str,
) -> Result<String, NoteError> {
// Deserialize.
// Render Body.
let input = self.content.body();
// If this variable is set, overwrite `file_ext`
let fm_file_ext = match self.context.get(TMPL_VAR_FM_FILE_EXT) {
Some(tera::Value::String(fm_file_ext)) => fm_file_ext.as_str(),
_ => "",
};
// Render the markup language.
let html_output = match MarkupLanguage::from(fm_file_ext).or(MarkupLanguage::from(file_ext))
{
#[cfg(feature = "renderer")]
MarkupLanguage::Markdown => Self::render_md_content(input),
#[cfg(feature = "renderer")]
MarkupLanguage::RestructuredText => Self::render_rst_content(input)?,
MarkupLanguage::Html => input.to_string(),
_ => Self::render_txt_content(input),
};
let mut html_context = self.context.clone();
// Register rendered body.
html_context.insert(TMPL_HTML_VAR_NOTE_BODY_HTML, &html_output);
// Insert the raw CSS
html_context.insert(
TMPL_HTML_VAR_NOTE_CSS,
&LIB_CFG.read().unwrap().tmpl_html.css,
);
// Insert the web server path to get the CSS loaded.
html_context.insert(
TMPL_HTML_VAR_NOTE_CSS_PATH,
TMPL_HTML_VAR_NOTE_CSS_PATH_VALUE,
);
let mut tera = Tera::default();
tera.extend(&TERA)?;
let html = tera.render_str(tmpl, &html_context).map_err(|e| {
note_error_tera_template!(e, "[html_tmpl] viewer/exporter_tmpl ".to_string())
})?;
Ok(html)
}Trait Implementations§
source§impl Clone for MarkupLanguage
impl Clone for MarkupLanguage
source§fn clone(&self) -> MarkupLanguage
fn clone(&self) -> MarkupLanguage
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl Debug for MarkupLanguage
impl Debug for MarkupLanguage
source§impl From<&Path> for MarkupLanguage
impl From<&Path> for MarkupLanguage
source§impl From<&str> for MarkupLanguage
impl From<&str> for MarkupLanguage
source§impl PartialEq<MarkupLanguage> for MarkupLanguage
impl PartialEq<MarkupLanguage> for MarkupLanguage
source§fn eq(&self, other: &MarkupLanguage) -> bool
fn eq(&self, other: &MarkupLanguage) -> bool
This method tests for
self and other values to be equal, and is used
by ==.impl Eq for MarkupLanguage
impl StructuralEq for MarkupLanguage
impl StructuralPartialEq for MarkupLanguage
Auto Trait Implementations§
impl RefUnwindSafe for MarkupLanguage
impl Send for MarkupLanguage
impl Sync for MarkupLanguage
impl Unpin for MarkupLanguage
impl UnwindSafe for MarkupLanguage
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.