Make Oblique no longer a context, add a point module
This commit is contained in:
parent
de5b3dd377
commit
315956e20d
4 changed files with 58 additions and 20 deletions
|
|
@ -23,7 +23,6 @@ pub enum Block {
|
|||
pub enum Inline {
|
||||
Anchor,
|
||||
Code,
|
||||
Oblique,
|
||||
None,
|
||||
}
|
||||
|
||||
|
|
|
|||
40
src/syntax/content/parser/point.rs
Normal file
40
src/syntax/content/parser/point.rs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
use crate::syntax::content::{
|
||||
Parseable as _,
|
||||
parser::{
|
||||
lexeme::Lexeme,
|
||||
token::{Token, oblique::Oblique},
|
||||
state::State,
|
||||
},
|
||||
};
|
||||
|
||||
pub fn puncture(
|
||||
lexeme: &Lexeme,
|
||||
state: &mut State,
|
||||
tokens: &mut Vec<Token>,
|
||||
) -> bool {
|
||||
if Oblique::probe(lexeme) {
|
||||
tokens.push(Token::Oblique(Oblique::new(!state.switches.oblique)));
|
||||
state.switches.oblique = !state.switches.oblique;
|
||||
return true;
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{syntax::content::parser, types::Graph};
|
||||
|
||||
fn read_noconfig(input: &str) -> String {
|
||||
parser::read(input, &Graph::new(None).meta.config)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn oblique() {
|
||||
assert_eq!(
|
||||
read_noconfig(
|
||||
"_|this anchor is oblique|o as are these literals_ but not these _just these_, not this _and these with an |anchor| again_"
|
||||
),
|
||||
r#"<p><em><a href="/node/o">this anchor is oblique</a> as are these literals</em> but not these <em>just these</em>, not this <em>and these with an <a href="/node/anchor">anchor</a> again</em></p>"#
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -9,9 +9,15 @@ use crate::syntax::content::parser::{
|
|||
pub struct State {
|
||||
pub context: Context,
|
||||
pub dom_ids: HashMap<String, Vec<String>>,
|
||||
pub switches: Switches,
|
||||
pub buffers: Buffers,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Switches {
|
||||
pub oblique: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Buffers {
|
||||
pub anchor: AnchorBuffer,
|
||||
|
|
@ -56,14 +62,15 @@ impl std::fmt::Display for AnchorBuffer {
|
|||
}
|
||||
}
|
||||
|
||||
impl State {
|
||||
pub fn new() -> State {
|
||||
impl Default for State {
|
||||
fn default() -> State {
|
||||
State {
|
||||
context: Context {
|
||||
inline: Inline::None,
|
||||
block: Block::None,
|
||||
},
|
||||
dom_ids: HashMap::new(),
|
||||
switches: Switches { oblique: false },
|
||||
buffers: Buffers {
|
||||
anchor: AnchorBuffer {
|
||||
candidate: Anchor::default(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue