Comments (5)
A benefit of having a trait could be to enable reuse of the adapter between std::io::Write/std::fmt::Write. However, here it looks like you need to implement both methods.
We have a html::Writer object that could potentially implement some trait, e.g:
pub trait Render {
// implement this
fn write_fmt<'s, I: Iterator<Item = Event<'s>>, W: std::fmt::Write>(
&mut self,
events: I,
out: W,
) -> std::fmt::Result;
// and get these for free
fn push<'s, I: Iterator<Item = Event<'s>>, W: std::fmt::Write>(&mut self, events: I, out: W) {
self.write_fmt(events, out).unwrap();
}
fn write<'s, I: Iterator<Item = Event<'s>>, W: std::io::Write>(
&mut self,
events: I,
out: W,
) -> std::io::Result<()> {
// adapter stuff here
self.write_fmt(events, &mut output)
.map_err(|_| output.error.unwrap_err())
}
}
Then you have a mutable reference, so you can configure it if needed when constructing it.
from jotdown.
Yes, using the adapter is a great suggestion! Is there a reason why you are unwrapping the error in push
? I guess it's since Djot parsing can't really error, but we may want to give renderers the possibility to throw an error either way. Maybe we only need push
and write
then, push
being the required implementation?
from jotdown.
Is there a reason why you are unwrapping the error in
push
? I guess it's since Djot parsing can't really error, but we may want to give renderers the possibility to throw an error either way.
Yeah, I think the html::Writer does not cause formatting errors at least because it always uses the write! macro which is checked at compile time. But I guess there is nothing stopping the std::fmt::Write implementor from causing an error when we try to write to it. Usually it is just a string which should never cause an error on writing to it, but it could be anything, I guess? So I guess we should not unwrap, and just propagate the result instead.
Maybe we only need
push
andwrite
then,push
being the required implementation?
Yeah, that is a better idea, we should only need those two.
from jotdown.
Awesome! In that case, I'll draft this out tomorrow and open a PR where we can have a look at this.
from jotdown.
Closed by #12
from jotdown.
Related Issues (20)
- Emit events for link definitions HOT 4
- bug: attributes disappear from raw inline
- Add an AST HOT 5
- bug: disappearing attributes
- CowStr HOT 2
- Provide C API HOT 2
- bug: formatting is kept in link reference text tag
- Render from borrowed events? HOT 3
- Expose tag for unresolved links in Event
- Emit Footnotes as they are encountered
- impl IntoIterator for Attributes HOT 2
- bug: consecutive attributes are ignored HOT 1
- Attributes are parsed inside math HOT 2
- Comments don't work with headings HOT 1
- paragraph tags disappear after numbered list
- Ambiguity between alphabetical and Roman numeral lists HOT 3
- Provide a shortcut to just render to String HOT 2
- Escapes in inline links
- Multi-line block attributes
- `\` inside a table deletes the entire row from the table HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jotdown.