Add support for an org-entities global setting.

This commit is contained in:
Tom Alexander
2023-10-08 18:01:42 -04:00
parent 1df6777b0b
commit c150aa4dea
5 changed files with 474 additions and 454 deletions

View File

@@ -1,6 +1,8 @@
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use super::constants::DEFAULT_ORG_ENTITIES;
use super::constants::DEFAULT_ORG_LINK_PARAMETERS;
use super::FileAccessInterface;
use super::LocalFileAccessInterface;
use crate::types::IndentationLevel;
@@ -34,11 +36,6 @@ pub struct GlobalSettings<'g, 's> {
/// Corresponds to org-footnote-section elisp variable.
pub footnote_section: &'g str,
/// The label format for references inside src/example blocks.
///
/// Corresponds to org-coderef-label-format elisp variable.
pub coderef_label_format: &'g str,
/// The allowed protocols for links (for example, the "https" in "https://foo.bar/").
///
/// Corresponds to org-link-parameters elisp variable.
@@ -50,10 +47,26 @@ pub struct GlobalSettings<'g, 's> {
///
/// This is set by including #+LINK in the org-mode document.
pub link_templates: BTreeMap<String, String>,
/// The special characters that can be written in org-mode like \infin for the infinity symbol.
///
/// Corresponds to org-entities elisp variable.
pub entities: &'g [EntityDefinition<'g>],
}
pub const DEFAULT_TAB_WIDTH: IndentationLevel = 8;
#[derive(Debug, Clone)]
pub struct EntityDefinition<'a> {
pub name: &'a str,
pub latex_math_mode: bool,
pub latex: &'a str,
pub html: &'a str,
pub ascii: &'a str,
// Skipping latin1 because it is detrimental to the future. If anyone out there is using latin1, take a long look in the mirror and change your ways.
pub utf8: &'a str,
}
impl<'g, 's> GlobalSettings<'g, 's> {
fn new() -> GlobalSettings<'g, 's> {
GlobalSettings {
@@ -67,9 +80,9 @@ impl<'g, 's> GlobalSettings<'g, 's> {
tab_width: DEFAULT_TAB_WIDTH,
odd_levels_only: HeadlineLevelFilter::default(),
footnote_section: "Footnotes",
coderef_label_format: "(ref:%s)",
link_parameters: &DEFAULT_ORG_LINK_PARAMETERS,
link_templates: BTreeMap::new(),
entities: &DEFAULT_ORG_ENTITIES,
}
}
}
@@ -91,29 +104,3 @@ impl Default for HeadlineLevelFilter {
HeadlineLevelFilter::OddEven
}
}
const DEFAULT_ORG_LINK_PARAMETERS: [&'static str; 23] = [
"id",
"eww",
"rmail",
"mhe",
"irc",
"info",
"gnus",
"docview",
"bibtex",
"bbdb",
"w3m",
"doi",
"file+sys",
"file+emacs",
"shell",
"news",
"mailto",
"https",
"http",
"ftp",
"help",
"file",
"elisp",
];