Skip to content

Parse style from <style> tag and Add support to <line> tag#1719

Merged
3b1b merged 6 commits intomasterfrom
parse-style
Jan 27, 2022
Merged

Parse style from <style> tag and Add support to <line> tag#1719
3b1b merged 6 commits intomasterfrom
parse-style

Conversation

@TonyCrane
Copy link
Collaborator

Motivation

#1717 (comment)
I solved this issue. Use tinycss2 to parse style (including <style> tag and style attributes in other tags), and use cssselect2 to choose which tag to apply to based on selector.
And in order to make cssselect2 handle selectors correctly, I replaced xml.dom.minidom with xml.etree for parsing SVG file, which also has more features.

At the same time, I also implemented the processing of the <line> tag by the way.

Proposed changes

  • M manimlib/mobject/svg/svg_mobject.py: improve style parsing and implement the <line> tag
  • M setup.cfg & requirements.txt: add dependency of cssselect2(tinycss2 will be installed along with it)

Test

Code:

class Code(Scene):
    def construct(self):
        svg = SVGMobject("beer.svg", color=BLACK, height=6)
        self.add(svg)

Result:
image

Code:

class Code(Scene):
    def construct(self):
        svg = SVGMobject("line.svg")
        self.add(svg)

line

Result:
image

@TonyCrane TonyCrane requested a review from 3b1b January 27, 2022 13:56
@3b1b 3b1b merged commit f60dc7c into master Jan 27, 2022
@TonyCrane TonyCrane deleted the parse-style branch January 28, 2022 01:54
TonyCrane added a commit that referenced this pull request Jan 30, 2022
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