Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward all unknown attributes to latex lstlistings #116

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/backend/latex/complex/codeblock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl<'a> CodeGenUnit<'a, CodeBlock<'a>> for CodeBlockGen {
_cfg: &'a Config, code_block: WithRange<CodeBlock<'a>>,
gen: &mut Generator<'a, impl Backend<'a>, impl Write>,
) -> Result<Self> {
let WithRange(CodeBlock { label, caption, language }, _range) = code_block;
let WithRange(CodeBlock { label, caption, language, attributes }, _range) = code_block;

let mut out = gen.get_out();
write!(out, "\\begin{{lstlisting}}[")?;
Expand All @@ -35,6 +35,11 @@ impl<'a> CodeGenUnit<'a, CodeBlock<'a>> for CodeBlockGen {
};
joiner.join(format_args!("language={{{}}}", language))?;
}
if !attributes.is_empty() {
for (k, v) in attributes {
joiner.join(format_args!("{}={{{}}}", k, v.0))?;
}
}
writeln!(out, "]")?;

Ok(CodeBlockGen)
Expand Down
6 changes: 5 additions & 1 deletion src/cskvp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ impl<'a> Cskvp<'a> {
self.double.remove(key)
}

pub fn take_all_double(&mut self) -> HashMap<Cow<'a, str>, WithRange<Cow<'a, str>>> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Drop we warn for all unused attributes of a Cskvp. Using this method makes that more or less pointless.

self.double.drain().collect()
}

/// Removes all elements from `self`.
///
/// This can be used before dropping `Cskvp` to omit all "unused attribute" warnings.
Expand All @@ -179,7 +183,7 @@ impl<'a> Drop for Cskvp<'a> {
let mut diag = self
.diagnostics
.as_mut()
.map(|d| d.warning("unknown attributes in element config")
.map(|d| d.warning("unused / unknown attributes in element config")
.with_info_section(range, "in this element config"));
if let Some(WithRange(label, range)) = self.label.take() {
diag = diag.map(|d| {
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use enum_kinds::EnumKind;

use crate::frontend::range::WithRange;
use crate::resolve::{Command, ResolveSecurity};
use std::collections::HashMap;

// extension of pulldown_cmark::Event with custom types
#[derive(Debug, EnumKind)]
Expand Down Expand Up @@ -111,6 +112,7 @@ pub struct CodeBlock<'a> {
pub label: Option<WithRange<Cow<'a, str>>>,
pub caption: Option<WithRange<Cow<'a, str>>>,
pub language: Option<WithRange<Cow<'a, str>>>,
pub attributes: HashMap<Cow<'a, str>, WithRange<Cow<'a, str>>>,
}

#[derive(Debug, Clone)]
Expand Down
1 change: 1 addition & 0 deletions src/frontend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ impl<'a> Frontend<'a> {
} else {
Some(WithRange(language, language_range))
},
attributes: cskvp.take_all_double(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could take some inspiration from html, and have a style attribute instead that contains options that should be forwarded? I'm not completely sure either.

}),
};

Expand Down