@@ -24,53 +24,53 @@ namespace HtmlToOpenXml.Expressions;
24
24
abstract class HtmlDomExpression
25
25
{
26
26
protected const string InternalNamespaceUri = "https://github.com/onizet/html2openxml" ;
27
- static readonly Dictionary < string , Func < IHtmlElement , HtmlElementExpression > > knownTags = InitKnownTags ( ) ;
27
+ static readonly Dictionary < string , Func < IElement , HtmlDomExpression > > knownTags = InitKnownTags ( ) ;
28
28
static readonly HashSet < string > ignoreTags = new ( StringComparer . OrdinalIgnoreCase ) {
29
29
TagNames . Xml , TagNames . AnnotationXml , TagNames . Button , TagNames . Progress ,
30
30
TagNames . Select , TagNames . Input , TagNames . Textarea , TagNames . Meter } ;
31
31
32
- private static Dictionary < string , Func < IHtmlElement , HtmlElementExpression > > InitKnownTags ( )
32
+ private static Dictionary < string , Func < IElement , HtmlDomExpression > > InitKnownTags ( )
33
33
{
34
34
// A complete list of HTML tags can be found here: http://www.w3schools.com/tags/default.asp
35
35
36
- var knownTags = new Dictionary < string , Func < IHtmlElement , HtmlElementExpression > > ( StringComparer . InvariantCultureIgnoreCase ) {
37
- { TagNames . A , el => new HyperlinkExpression ( el ) } ,
38
- { TagNames . Abbr , el => new AbbreviationExpression ( el ) } ,
39
- { "acronym" , el => new AbbreviationExpression ( el ) } ,
40
- { TagNames . B , el => new PhrasingElementExpression ( el , new Bold ( ) ) } ,
41
- { TagNames . BlockQuote , el => new BlockQuoteExpression ( el ) } ,
42
- { TagNames . Br , el => new LineBreakExpression ( el ) } ,
43
- { TagNames . Cite , el => new CiteElementExpression ( el ) } ,
44
- { TagNames . Dd , el => new BlockElementExpression ( el , new Indentation ( ) { FirstLine = "708" } , new SpacingBetweenLines ( ) { After = "0" } ) } ,
45
- { TagNames . Del , el => new PhrasingElementExpression ( el , new Strike ( ) ) } ,
46
- { TagNames . Dfn , el => new AbbreviationExpression ( el ) } ,
47
- { TagNames . Em , el => new PhrasingElementExpression ( el , new Italic ( ) ) } ,
48
- { TagNames . Figcaption , el => new FigureCaptionExpression ( el ) } ,
49
- { TagNames . Font , el => new FontElementExpression ( el ) } ,
50
- { TagNames . H1 , el => new HeadingElementExpression ( el ) } ,
51
- { TagNames . H2 , el => new HeadingElementExpression ( el ) } ,
52
- { TagNames . H3 , el => new HeadingElementExpression ( el ) } ,
53
- { TagNames . H4 , el => new HeadingElementExpression ( el ) } ,
54
- { TagNames . H5 , el => new HeadingElementExpression ( el ) } ,
55
- { TagNames . H6 , el => new HeadingElementExpression ( el ) } ,
56
- { TagNames . I , el => new PhrasingElementExpression ( el , new Italic ( ) ) } ,
57
- { TagNames . Hr , el => new HorizontalLineExpression ( el ) } ,
58
- { TagNames . Img , el => new ImageExpression ( el ) } ,
59
- { TagNames . Ins , el => new PhrasingElementExpression ( el , new Underline ( ) { Val = UnderlineValues . Single } ) } ,
60
- { TagNames . Ol , el => new ListExpression ( el ) } ,
61
- { TagNames . Pre , el => new PreElementExpression ( el ) } ,
62
- { TagNames . Q , el => new QuoteElementExpression ( el ) } ,
63
- { TagNames . Quote , el => new QuoteElementExpression ( el ) } ,
64
- { TagNames . Span , el => new PhrasingElementExpression ( el ) } ,
65
- { TagNames . S , el => new PhrasingElementExpression ( el , new Strike ( ) ) } ,
66
- { TagNames . Strike , el => new PhrasingElementExpression ( el , new Strike ( ) ) } ,
67
- { TagNames . Strong , el => new PhrasingElementExpression ( el , new Bold ( ) ) } ,
68
- { TagNames . Sub , el => new PhrasingElementExpression ( el , new VerticalTextAlignment ( ) { Val = VerticalPositionValues . Subscript } ) } ,
69
- { TagNames . Sup , el => new PhrasingElementExpression ( el , new VerticalTextAlignment ( ) { Val = VerticalPositionValues . Superscript } ) } ,
70
- { TagNames . Table , el => new TableExpression ( el ) } ,
71
- { TagNames . Time , el => new PhrasingElementExpression ( el ) } ,
72
- { TagNames . U , el => new PhrasingElementExpression ( el , new Underline ( ) { Val = UnderlineValues . Single } ) } ,
73
- { TagNames . Ul , el => new ListExpression ( el ) } ,
36
+ var knownTags = new Dictionary < string , Func < IElement , HtmlDomExpression > > ( StringComparer . InvariantCultureIgnoreCase ) {
37
+ { TagNames . A , el => new HyperlinkExpression ( ( IHtmlAnchorElement ) el ) } ,
38
+ { TagNames . Abbr , el => new AbbreviationExpression ( ( IHtmlElement ) el ) } ,
39
+ { "acronym" , el => new AbbreviationExpression ( ( IHtmlElement ) el ) } ,
40
+ { TagNames . B , el => new PhrasingElementExpression ( ( IHtmlElement ) el , new Bold ( ) ) } ,
41
+ { TagNames . BlockQuote , el => new BlockQuoteExpression ( ( IHtmlElement ) el ) } ,
42
+ { TagNames . Br , _ => new LineBreakExpression ( ) } ,
43
+ { TagNames . Cite , el => new CiteElementExpression ( ( IHtmlElement ) el ) } ,
44
+ { TagNames . Dd , el => new BlockElementExpression ( ( IHtmlElement ) el , new Indentation ( ) { FirstLine = "708" } , new SpacingBetweenLines ( ) { After = "0" } ) } ,
45
+ { TagNames . Del , el => new PhrasingElementExpression ( ( IHtmlElement ) el , new Strike ( ) ) } ,
46
+ { TagNames . Dfn , el => new AbbreviationExpression ( ( IHtmlElement ) el ) } ,
47
+ { TagNames . Em , el => new PhrasingElementExpression ( ( IHtmlElement ) el , new Italic ( ) ) } ,
48
+ { TagNames . Figcaption , el => new FigureCaptionExpression ( ( IHtmlElement ) el ) } ,
49
+ { TagNames . Font , el => new FontElementExpression ( ( IHtmlElement ) el ) } ,
50
+ { TagNames . H1 , el => new HeadingElementExpression ( ( IHtmlElement ) el ) } ,
51
+ { TagNames . H2 , el => new HeadingElementExpression ( ( IHtmlElement ) el ) } ,
52
+ { TagNames . H3 , el => new HeadingElementExpression ( ( IHtmlElement ) el ) } ,
53
+ { TagNames . H4 , el => new HeadingElementExpression ( ( IHtmlElement ) el ) } ,
54
+ { TagNames . H5 , el => new HeadingElementExpression ( ( IHtmlElement ) el ) } ,
55
+ { TagNames . H6 , el => new HeadingElementExpression ( ( IHtmlElement ) el ) } ,
56
+ { TagNames . I , el => new PhrasingElementExpression ( ( IHtmlElement ) el , new Italic ( ) ) } ,
57
+ { TagNames . Hr , el => new HorizontalLineExpression ( ( IHtmlElement ) el ) } ,
58
+ { TagNames . Img , el => new ImageExpression ( ( IHtmlImageElement ) el ) } ,
59
+ { TagNames . Ins , el => new PhrasingElementExpression ( ( IHtmlElement ) el , new Underline ( ) { Val = UnderlineValues . Single } ) } ,
60
+ { TagNames . Ol , el => new ListExpression ( ( IHtmlElement ) el ) } ,
61
+ { TagNames . Pre , el => new PreElementExpression ( ( IHtmlElement ) el ) } ,
62
+ { TagNames . Q , el => new QuoteElementExpression ( ( IHtmlElement ) el ) } ,
63
+ { TagNames . Quote , el => new QuoteElementExpression ( ( IHtmlElement ) el ) } ,
64
+ { TagNames . Span , el => new PhrasingElementExpression ( ( IHtmlElement ) el ) } ,
65
+ { TagNames . S , el => new PhrasingElementExpression ( ( IHtmlElement ) el , new Strike ( ) ) } ,
66
+ { TagNames . Strike , el => new PhrasingElementExpression ( ( IHtmlElement ) el , new Strike ( ) ) } ,
67
+ { TagNames . Strong , el => new PhrasingElementExpression ( ( IHtmlElement ) el , new Bold ( ) ) } ,
68
+ { TagNames . Sub , el => new PhrasingElementExpression ( ( IHtmlElement ) el , new VerticalTextAlignment ( ) { Val = VerticalPositionValues . Subscript } ) } ,
69
+ { TagNames . Sup , el => new PhrasingElementExpression ( ( IHtmlElement ) el , new VerticalTextAlignment ( ) { Val = VerticalPositionValues . Superscript } ) } ,
70
+ { TagNames . Table , el => new TableExpression ( ( IHtmlTableElement ) el ) } ,
71
+ { TagNames . Time , el => new PhrasingElementExpression ( ( IHtmlElement ) el ) } ,
72
+ { TagNames . U , el => new PhrasingElementExpression ( ( IHtmlElement ) el , new Underline ( ) { Val = UnderlineValues . Single } ) } ,
73
+ { TagNames . Ul , el => new ListExpression ( ( IHtmlElement ) el ) } ,
74
74
} ;
75
75
76
76
return knownTags ;
@@ -93,8 +93,8 @@ private static Dictionary<string, Func<IHtmlElement, HtmlElementExpression>> Ini
93
93
else if ( node . NodeType == NodeType . Element
94
94
&& ! ignoreTags . Contains ( node . NodeName ) )
95
95
{
96
- if ( knownTags . TryGetValue ( node . NodeName , out Func < IHtmlElement , HtmlElementExpression > ? handler ) )
97
- return handler ( ( IHtmlElement ) node ) ;
96
+ if ( knownTags . TryGetValue ( node . NodeName , out Func < IElement , HtmlDomExpression > ? handler ) )
97
+ return handler ( ( IElement ) node ) ;
98
98
99
99
// fallback on the flow element which will cover all the semantic Html5 tags
100
100
return new BlockElementExpression ( ( IHtmlElement ) node ) ;
0 commit comments