From 2439ddfffd748e247cf0b412114c68a0e52aed86 Mon Sep 17 00:00:00 2001 From: Jonas Baumann Date: Thu, 3 Jan 2013 15:57:50 +0100 Subject: [PATCH 1/5] rst: use CSS for image alignment. --- lib/github/commands/rest2html | 17 +++++++++++++++++ test/markups/README.rst | 2 ++ test/markups/README.rst.html | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/github/commands/rest2html b/lib/github/commands/rest2html index 0efea607..107f2a0b 100755 --- a/lib/github/commands/rest2html +++ b/lib/github/commands/rest2html @@ -207,6 +207,23 @@ class GitHubHTMLTranslator(HTMLTranslator): def depart_table(self, node): self.body.append('\n') + def visit_image(self, node): + """Custom visit_image for using the HTML align attribute for + image alignment, since css-classes will be stripped. + """ + HTMLTranslator.visit_image(self, node) + if self.body[-1].startswith('', ' style="float: %s" />' % align) + def depart_image(self, node): uri = node['uri'] ext = os.path.splitext(uri)[1].lower() diff --git a/test/markups/README.rst b/test/markups/README.rst index 54bd71ce..8488f19d 100644 --- a/test/markups/README.rst +++ b/test/markups/README.rst @@ -76,6 +76,8 @@ someone@somewhere.org Press :kbd:`Ctrl+C` to quit +.. image:: foo.png + :align: right .. raw:: html diff --git a/test/markups/README.rst.html b/test/markups/README.rst.html index 7b8e9fca..67bf9433 100644 --- a/test/markups/README.rst.html +++ b/test/markups/README.rst.html @@ -91,5 +91,5 @@

Field list

someone@somewhere.org

Press Ctrl+C to quit

- +foo.png

RAW HTML!

p {color:blue;} From a9d8899aa6f7857804d65c9d1327f7aae4271582 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Sat, 3 Apr 2021 11:35:19 +0200 Subject: [PATCH 2/5] Fix tests? --- test/markups/README.rst.html | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/markups/README.rst.html b/test/markups/README.rst.html index fb2c3e37..903a4caa 100644 --- a/test/markups/README.rst.html +++ b/test/markups/README.rst.html @@ -131,9 +131,7 @@

Field list

-

someone@somewhere.org

-

Press Ctrl+C to quit

foo.png

RAW HTML!

p {color:blue;} From c8de62f86438179fcef21bd80dc62655b22d6ea0 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Sat, 3 Apr 2021 11:39:52 +0200 Subject: [PATCH 3/5] img has no /> anymore --- lib/github/commands/rest2html | 3 ++- test/markups/README.rst.html | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/github/commands/rest2html b/lib/github/commands/rest2html index 1f4f52a1..afeb3b8d 100755 --- a/lib/github/commands/rest2html +++ b/lib/github/commands/rest2html @@ -251,7 +251,8 @@ class GitHubHTMLTranslator(HTMLTranslator): if align: self.body[-1] = self.body[-1].replace( - ' />', ' style="float: %s" />' % align) + '>', ' style="float: %s">' % align + ) def depart_image(self, node): uri = node['uri'] diff --git a/test/markups/README.rst.html b/test/markups/README.rst.html index 903a4caa..f542fdbf 100644 --- a/test/markups/README.rst.html +++ b/test/markups/README.rst.html @@ -133,5 +133,5 @@

Field list

someone@somewhere.org

Press Ctrl+C to quit

-foo.png -

RAW HTML!

p {color:blue;} +foo.png +

RAW HTML!

p {color:blue;} \ No newline at end of file From 7bf880d70564a1c174ede2cea0d48393094263b0 Mon Sep 17 00:00:00 2001 From: Philipp A Date: Sat, 3 Apr 2021 11:46:46 +0200 Subject: [PATCH 4/5] wait a sec --- lib/github/commands/rest2html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/github/commands/rest2html b/lib/github/commands/rest2html index afeb3b8d..68c2c4b1 100755 --- a/lib/github/commands/rest2html +++ b/lib/github/commands/rest2html @@ -251,7 +251,7 @@ class GitHubHTMLTranslator(HTMLTranslator): if align: self.body[-1] = self.body[-1].replace( - '>', ' style="float: %s">' % align + ' />', ' style="float: %s" />' % align ) def depart_image(self, node): From fa8bceb4339c2aed0ea4608601a8c96cfa98fe9c Mon Sep 17 00:00:00 2001 From: Philipp A Date: Sat, 3 Apr 2021 12:26:24 +0200 Subject: [PATCH 5/5] handle existing style tag --- lib/github/commands/rest2html | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/github/commands/rest2html b/lib/github/commands/rest2html index 68c2c4b1..2dc7e2ac 100755 --- a/lib/github/commands/rest2html +++ b/lib/github/commands/rest2html @@ -250,9 +250,11 @@ class GitHubHTMLTranslator(HTMLTranslator): align = node.parent.get('align') if align: - self.body[-1] = self.body[-1].replace( - ' />', ' style="float: %s" />' % align - ) + if ' style="' in self.body[-1]: + old, new = ' style="', ' style="float: %s; ' % align + else: + old, new = ' />', ' style="float: %s" />' % align + self.body[-1] = self.body[-1].replace(old, new) def depart_image(self, node): uri = node['uri']