This issue describes the changes to the wiki::parser module already outlined in #216. The main goal is to remove any outside dependencies (cursive and the use of the global CONFIG) from the parser. The few dependencies we may need should be injected (dependency injection) to simplify the testing of the parser.
To remove the dependency from the cursive crate, we would need to either remove the Effect and Style values from the Element or create our own.
I believe we should remove the styling from the parser altogether because the parser really should only create a tree of elements from the HTML page and nothing more. The colors and formatting should be done by the renderer (LinesWrapper).
That means the Element should only include the id,kind, content, width and attributes. The style attribute is no longer needed. We also need a way of specifying the effects of the element meaning we need a custom Effect struct.
Because we have to sometimes declare the start and end of different objects such as lists or disambiguations, the element struct should be an Enum with two different options: Content and Meta. Element::Content would contain the standard element attributes like width and id and Element::Meta would contain a value of another enum containing the different Meta values.
For some elements, we need extra information (the anchor for headers, the url for links, etc.). We could embed them in the ElementKind enum. For a link it could look like this
enum ElementKind {
Link { link: link::Link },
...
When we want to render the returned tree of elements, we can store the current context and apply padding, styling, etc. as needed.
That means we need to do the following things:
[ ] Remove the style attribute from Element
[ ] Create Effect enum and add it to Element
[ ] Create ElementMeta and modify ElementKind
[ ] Move Element into an enum
[ ] Create tests for the new parser
[ ] Modify Parser and LinesWrapper to fix parsing and rendering
Linked to #216
This issue describes the changes to the
wiki::parser
module already outlined in #216. The main goal is to remove any outside dependencies (cursive
and the use of the globalCONFIG
) from the parser. The few dependencies we may need should be injected (dependency injection) to simplify the testing of the parser.To remove the dependency from the
cursive
crate, we would need to either remove theEffect
andStyle
values from theElement
or create our own.I believe we should remove the styling from the parser altogether because the parser really should only create a tree of elements from the HTML page and nothing more. The colors and formatting should be done by the renderer (
LinesWrapper
).That means the
Element
should only include theid
,kind
,content
,width
andattributes
. Thestyle
attribute is no longer needed. We also need a way of specifying the effects of the element meaning we need a customEffect
struct.Because we have to sometimes declare the start and end of different objects such as lists or disambiguations, the element struct should be an Enum with two different options: Content and Meta.
Element::Content
would contain the standard element attributes likewidth
andid
andElement::Meta
would contain a value of another enum containing the different Meta values.Below is a first structure
For some elements, we need extra information (the anchor for headers, the url for links, etc.). We could embed them in the
ElementKind
enum. For a link it could look like thisWhen we want to render the returned tree of elements, we can store the current context and apply padding, styling, etc. as needed.
That means we need to do the following things:
style
attribute fromElement
Effect
enum and add it toElement
ElementMeta
and modifyElementKind
Element
into an enumParser
andLinesWrapper
to fix parsing and rendering