Skip to content

Commit

Permalink
Update pulldown cmark to 0.10 (#68)
Browse files Browse the repository at this point in the history
* Fix clippy warnings

* Fix formating

* Update pulldown-cmark to 0.10
  • Loading branch information
grego authored Mar 18, 2024
1 parent 02482cc commit f3a53de
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 126 deletions.
2 changes: 1 addition & 1 deletion ramhorns-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub fn content_derive(input: TokenStream) -> TokenStream {
if let Some(path) = ramhorns.callback {
callback = Some(path);
}
},
}
Ok(None) => (),
Err(err) => errors.push(err),
};
Expand Down
2 changes: 1 addition & 1 deletion ramhorns/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ categories = ["template-engine"]
arrayvec = "0.7.2"
beef = "0.5.2"
fnv = "1.0"
pulldown-cmark = { version = "0.9", default_features = false, optional = true }
pulldown-cmark = { version = "0.10", default_features = false, features = ["html"], optional = true }
ramhorns-derive = { version = "0.14.0", optional = true }
logos = "0.13.0"

Expand Down
62 changes: 11 additions & 51 deletions ramhorns/src/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use crate::encoding::Encoder;
use crate::template::{Section, Template};
use crate::traits::{ContentSequence};
use crate::traits::ContentSequence;

use arrayvec::ArrayVec;
use std::borrow::{Borrow, Cow, ToOwned};
Expand Down Expand Up @@ -52,11 +52,7 @@ pub trait Content {

/// Render a section with self.
#[inline]
fn render_section<C, E>(
&self,
section: Section<C>,
encoder: &mut E,
) -> Result<(), E::Error>
fn render_section<C, E>(&self, section: Section<C>, encoder: &mut E) -> Result<(), E::Error>
where
C: ContentSequence,
E: Encoder,
Expand All @@ -70,11 +66,7 @@ pub trait Content {

/// Render a section with self.
#[inline]
fn render_inverse<C, E>(
&self,
section: Section<C>,
encoder: &mut E,
) -> Result<(), E::Error>
fn render_inverse<C, E>(&self, section: Section<C>, encoder: &mut E) -> Result<(), E::Error>
where
C: ContentSequence,
E: Encoder,
Expand Down Expand Up @@ -316,11 +308,7 @@ impl<T: Content> Content for Option<T> {
}

#[inline]
fn render_section<C, E>(
&self,
section: Section<C>,
encoder: &mut E,
) -> Result<(), E::Error>
fn render_section<C, E>(&self, section: Section<C>, encoder: &mut E) -> Result<(), E::Error>
where
C: ContentSequence,
E: Encoder,
Expand Down Expand Up @@ -366,11 +354,7 @@ impl<T: Content, U> Content for Result<T, U> {
}

#[inline]
fn render_section<C, E>(
&self,
section: Section<C>,
encoder: &mut E,
) -> Result<(), E::Error>
fn render_section<C, E>(&self, section: Section<C>, encoder: &mut E) -> Result<(), E::Error>
where
C: ContentSequence,
E: Encoder,
Expand All @@ -390,11 +374,7 @@ impl<T: Content> Content for Vec<T> {
}

#[inline]
fn render_section<C, E>(
&self,
section: Section<C>,
encoder: &mut E,
) -> Result<(), E::Error>
fn render_section<C, E>(&self, section: Section<C>, encoder: &mut E) -> Result<(), E::Error>
where
C: ContentSequence,
E: Encoder,
Expand All @@ -414,11 +394,7 @@ impl<T: Content> Content for [T] {
}

#[inline]
fn render_section<C, E>(
&self,
section: Section<C>,
encoder: &mut E,
) -> Result<(), E::Error>
fn render_section<C, E>(&self, section: Section<C>, encoder: &mut E) -> Result<(), E::Error>
where
C: ContentSequence,
E: Encoder,
Expand All @@ -438,11 +414,7 @@ impl<T: Content, const N: usize> Content for [T; N] {
}

#[inline]
fn render_section<C, E>(
&self,
section: Section<C>,
encoder: &mut E,
) -> Result<(), E::Error>
fn render_section<C, E>(&self, section: Section<C>, encoder: &mut E) -> Result<(), E::Error>
where
C: ContentSequence,
E: Encoder,
Expand All @@ -462,11 +434,7 @@ impl<T: Content, const N: usize> Content for ArrayVec<T, N> {
}

#[inline]
fn render_section<C, E>(
&self,
section: Section<C>,
encoder: &mut E,
) -> Result<(), E::Error>
fn render_section<C, E>(&self, section: Section<C>, encoder: &mut E) -> Result<(), E::Error>
where
C: ContentSequence,
E: Encoder,
Expand All @@ -491,11 +459,7 @@ where

/// Render a section with self.
#[inline]
fn render_section<C, E>(
&self,
section: Section<C>,
encoder: &mut E,
) -> Result<(), E::Error>
fn render_section<C, E>(&self, section: Section<C>, encoder: &mut E) -> Result<(), E::Error>
where
C: ContentSequence,
E: Encoder,
Expand Down Expand Up @@ -578,11 +542,7 @@ where

/// Render a section with self.
#[inline]
fn render_section<C, E>(
&self,
section: Section<C>,
encoder: &mut E,
) -> Result<(), E::Error>
fn render_section<C, E>(&self, section: Section<C>, encoder: &mut E) -> Result<(), E::Error>
where
C: ContentSequence,
E: Encoder,
Expand Down
14 changes: 8 additions & 6 deletions ramhorns/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
//! Utilities dealing with writing the bits of a template or data to the output and
//! escaping special HTML characters.
use std::io;
use std::fmt;
use std::io;

#[cfg(feature = "pulldown-cmark")]
use pulldown_cmark::{html, Event, Parser};
Expand All @@ -30,7 +30,8 @@ pub trait Encoder {

#[cfg(feature = "pulldown-cmark")]
/// Write HTML from an `Iterator` of `pulldown_cmark` `Event`s.
fn write_html<'a, I: Iterator<Item = Event<'a>>>(&mut self, iter: I) -> Result<(), Self::Error>;
fn write_html<'a, I: Iterator<Item = Event<'a>>>(&mut self, iter: I)
-> Result<(), Self::Error>;

/// Write a `Display` implementor to this `Encoder` in plain mode.
fn format_unescaped<D: fmt::Display>(&mut self, display: D) -> Result<(), Self::Error>;
Expand Down Expand Up @@ -86,9 +87,7 @@ pub(crate) struct EscapingIOEncoder<W: io::Write> {
impl<W: io::Write> EscapingIOEncoder<W> {
#[inline]
pub fn new(inner: W) -> Self {
Self {
inner
}
Self { inner }
}

/// Same as `EscapingStringEncoder`, but dealing with byte arrays and writing to
Expand Down Expand Up @@ -190,7 +189,10 @@ impl Encoder for String {

#[cfg(feature = "pulldown-cmark")]
#[inline]
fn write_html<'a, I: Iterator<Item = Event<'a>>>(&mut self, iter: I) -> Result<(), Self::Error> {
fn write_html<'a, I: Iterator<Item = Event<'a>>>(
&mut self,
iter: I,
) -> Result<(), Self::Error> {
html::push_html(self, iter);

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion ramhorns/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl<H: BuildHasher + Default> Ramhorns<H> {
// Unsafe to expose as it loads the template from arbitrary path.
#[inline]
fn load_internal(&mut self, path: &Path, name: Cow<'static, str>) -> Result<(), Error> {
let file = match std::fs::read_to_string(&path) {
let file = match std::fs::read_to_string(path) {
Ok(file) => Ok(file),
Err(e) if e.kind() == ErrorKind::NotFound => {
Err(Error::NotFound(name.to_string().into()))
Expand Down
2 changes: 1 addition & 1 deletion ramhorns/src/template/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use crate::{Content, Error};
mod parse;
mod section;

pub use section::Section;
pub use parse::Tag;
pub use section::Section;

/// A preprocessed form of the plain text template, ready to be rendered
/// with data contained in types implementing the `Content` trait.
Expand Down
10 changes: 2 additions & 8 deletions ramhorns/src/template/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,13 @@ enum Closing {
}

/// Marker of how many braces we expect to match
#[derive(PartialEq, Eq, Clone, Copy)]
#[derive(PartialEq, Eq, Clone, Copy, Default)]
pub enum Braces {
#[default]
Two = 2,
Three = 3,
}

impl Default for Braces {
#[inline]
fn default() -> Self {
Braces::Two
}
}

impl<'tpl> Template<'tpl> {
pub(crate) fn parse(
&mut self,
Expand Down
11 changes: 6 additions & 5 deletions ramhorns/src/template/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

use super::{Block, Tag};
use crate::encoding::Encoder;
use crate::Content;
use crate::traits::{Combine, ContentSequence};
use crate::Content;
use std::ops::Range;

/// A section of a `Template` that can be rendered individually, usually delimited by
Expand Down Expand Up @@ -62,8 +62,7 @@ where

/// The section without the last `Content` in the stack
#[inline]
pub fn without_last(self) -> Section<'section, C::Previous>
{
pub fn without_last(self) -> Section<'section, C::Previous> {
Section {
blocks: self.blocks,
contents: self.contents.crawl_back(),
Expand All @@ -84,10 +83,12 @@ where

match block.tag {
Tag::Escaped => {
self.contents.render_field_escaped(block.hash, block.name, encoder)?;
self.contents
.render_field_escaped(block.hash, block.name, encoder)?;
}
Tag::Unescaped => {
self.contents.render_field_unescaped(block.hash, block.name, encoder)?;
self.contents
.render_field_unescaped(block.hash, block.name, encoder)?;
}
Tag::Section => {
self.contents.render_field_section(
Expand Down
8 changes: 4 additions & 4 deletions ramhorns/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ pub trait ContentSequence: Combine + Sized + Copy {

/// Render a field by the hash **or** string of its name, as a section.
#[inline]
fn render_field_section<'section, P, E>(
fn render_field_section<P, E>(
&self,
_hash: u64,
_name: &str,
_section: Section<'section, P>,
_section: Section<'_, P>,
_encoder: &mut E,
) -> Result<(), E::Error>
where
Expand All @@ -81,11 +81,11 @@ pub trait ContentSequence: Combine + Sized + Copy {

/// Render a field, by the hash of **or** string its name, as an inverse section.
#[inline]
fn render_field_inverse<'section, P, E>(
fn render_field_inverse<P, E>(
&self,
_hash: u64,
_name: &str,
_section: Section<'section, P>,
_section: Section<'_, P>,
_encoder: &mut E,
) -> Result<(), E::Error>
where
Expand Down
Loading

0 comments on commit f3a53de

Please sign in to comment.