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

Add support for basic HTML in popups #504

Merged
merged 3 commits into from
Mar 31, 2023

Conversation

mstefarov
Copy link
Collaborator

@mstefarov mstefarov commented Mar 30, 2023

  • Use a RichTextBox to display TextPopupElement contents
  • Strip HTML from popup titles (e.g. as seen in this webmap)

Everything listed here is supported except:

  • No audio/video playback yet. The fallback content is displayed instead (typically a link).
  • No tooltips yet (the title attribute is ignored).
  • Only simple tables are supported (colspan/rowspan/cellpadding/cellspacing/nowrap/width/height/valign attributes are ignored on table elements).
  • Customizing element borders is not supported (border attribute and css border properties are ignored).
  • Customizing padding and margin is not supported.
  • Images with base64 URIs not supported yet.
There are tests (not checked in yet)

2023-03-30_123450 devenv


Examples:
2023-03-30_125156 2023-03-30_125232
2023-03-30_125352 2023-03-30_125300

@mstefarov mstefarov requested a review from dotMorten March 30, 2023 19:51
@mstefarov mstefarov self-assigned this Mar 30, 2023
@mstefarov
Copy link
Collaborator Author

The conversion starts with raw popup text, e.g.

<p style='text-align:center;'><img src='https://inaturalist-open-data.s3.amazonaws.com/photos/117365592/medium.jpg?1616692245' alt='Specimen observed' width='250' /></p>
<p><strong>Figure.</strong> Dryobates villosus</p>
<hr />
<p><strong>Hairy Woodpecker</strong> belongs to the <span style='color:;'>Aves taxon</span> and are considered a non-captive/cultivated species within the Ottawa region. This particular specimen was observed on March 24, 2021.</p>

It is converted to a list of HtmlToken objects by HtmlTokenParser, e.g.

    OpenTag(p, "style='text-align:center;'")
    SelfClosingTag(img, "src='https://inaturalist-open-data.s3.amazonaws.com/photos/117365592/medium.jpg?1616692245' alt='Specimen observed' width='250'")
    CloseTag(p, null)
    OpenTag(p, null)
    OpenTag(strong, null)
    PlainText(Figure., null)
    CloseTag(strong, null)
    PlainText( Dryobates villosus, null)
    CloseTag(p, null)
    SelfClosingTag(hr, null)
    OpenTag(p, null)
    OpenTag(strong, null)
    PlainText(Hairy Woodpecker, null)
    CloseTag(strong, null)
    PlainText( belongs to the , null)
    OpenTag(span, "style='color:;'")
    PlainText(Aves taxon, null)
    CloseTag(span, null)
    PlainText( and are considered a non-captive/cultivated species within the Ottawa region. This particular specimen was observed on March 24, 2021., null)
    CloseTag(p, null)

Then tokens are built up into a tree of nodes by HtmlUtility.BuildDocumentTree:

    Document
      Block { align=Center }
        Image { text="https://inaturalist-open-data.s3.amazonaws.com/photos/117365592/medium.jpg?1616692245" }
      Block
        Span { bold=True }
          Text { text="Figure." }
        Text { text=" Dryobates villosus" }
      Divider
      Block
        Span { bold=True }
          Text { text="Hairy Woodpecker" }
        Text { text=" belongs to the " }
        Span
          Text { text="Aves taxon" }
        Text { text=" and are considered a non-captive/cultivated species within the Ottawa region. This particular specimen was observed on March 24, 2021." }

Everything up to this point has been cross-platform, UI-framework-agnostic code. The next and final step is to translate the node tree into WPF elements. This is done by TextPopupElementView. The produced FlowDocument has this structure:

FlowDocument
  Paragraph { TextAlignment = Center }
    InlineUIContainer
      Image
  Paragraph
    Span { FontWeight = Bold }
      Run { Text = "Figure." }
    Run { Text = " Dryobates villosus" }
  BlockUIContainer
    Separator
  Paragraph
    Span { FontWeight = Bold }
      Run { Text = "Hairy Woodpecker" }
    Run { Text = " belongs to the " }
    Span
      Run { Text = "Aves taxon" }
    Run { Text = " and are considered a non-captive/cultivated species within the Ottawa region. This particular specimen was observed on March 24, 2021." }

src/Toolkit/Toolkit/HtmlUtility.cs Outdated Show resolved Hide resolved
@mstefarov mstefarov merged commit 90fa11d into v.next Mar 31, 2023
@mstefarov mstefarov deleted the matvei/popupviewer-html-parsing branch March 31, 2023 00:34
dotMorten added a commit that referenced this pull request Apr 19, 2023
* v200.1

* WPF Popupviewer updates (#491)

* Switch to use PopupElements for popup viewer control

* Address namespace changes

* Update WindowsAppSDK version to match MAUI requirements (#500)

* Update deprecated property

* Add properties to allow compiling for .NET Framework

* Fix typo

* Avoid navigation string resources in toolkit package

* Updates relevant to popupviewer enhancements

(cherry picked from commit 273a7d7)

* Update README.md

Co-authored-by: Morten Nielsen <1378165+dotMorten@users.noreply.github.com>

* Update docs/popup-viewer.md

Co-authored-by: Morten Nielsen <1378165+dotMorten@users.noreply.github.com>

* Fix min-version support in MAUI

* Maui: Ensure fonts are packaged and deployed

* Add support for basic HTML in popups (#504)

* Work around asset deployment issues caused by WinAppSDK

See microsoft/WindowsAppSDK#3546 for details

* Also include assets in lib folder for library layout

Follow-up to work around issue microsoft/WindowsAppSDK#3546

* Set background on toolbar

---------

Co-authored-by: Morten Nielsen <mort5161@esri.com>
Co-authored-by: Matvei Stefarov <mstefarov@esri.com>
Co-authored-by: Preeti Maske <pmaske@esri.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants