emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH 1/3] add id attribute to example-block on html export.
@ 2016-03-28 19:06 John Kitchin
  2016-03-28 19:06 ` [PATCH 2/3] add html attributes to quote-block John Kitchin
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: John Kitchin @ 2016-03-28 19:06 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: John Kitchin

This allows you to hyperlink to the block.
---
 lisp/ox-html.el | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index d07cdcc..92de209 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -2370,14 +2370,23 @@ contextual information."
 
 ;;;; Example Block
 
-(defun org-html-example-block (example-block _contents info)
+(defun org-html-example-block (example-block contents info)
   "Transcode a EXAMPLE-BLOCK element from Org to HTML.
 CONTENTS is nil.  INFO is a plist holding contextual
 information."
   (if (org-export-read-attribute :attr_html example-block :textarea)
       (org-html--textarea-block example-block)
-    (format "<pre class=\"example\">\n%s</pre>"
-	    (org-html-format-code example-block info))))
+    (let ((attributes (org-export-read-attribute :attr_html example-block)))
+      (when (org-element-property :name example-block)
+	(setq attributes (plist-put
+			  attributes :id
+			  (org-element-property :name example-block))))
+      (setq attributes (org-html--make-attribute-string attributes))
+      (when (not (equal attributes ""))
+	(setq attributes (concat " " attributes)))
+      (format "<pre class=\"example\"%s>\n%s</pre>"
+	      attributes
+	      (org-html-format-code example-block info)))))
 
 ;;;; Export Snippet
 
-- 
2.4.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] add html attributes to quote-block
  2016-03-28 19:06 [PATCH 1/3] add id attribute to example-block on html export John Kitchin
@ 2016-03-28 19:06 ` John Kitchin
  2016-03-28 19:06 ` [PATCH 3/3] add html attributes to special blocks John Kitchin
  2016-03-30 15:03 ` [PATCH 1/3] add id attribute to example-block on html export Nicolas Goaziou
  2 siblings, 0 replies; 7+ messages in thread
From: John Kitchin @ 2016-03-28 19:06 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: John Kitchin

Enables #+attr_html: and puts a id attribute when the block is named into the html element.
---
 lisp/ox-html.el | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 92de209..5bdfc14 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -3155,11 +3155,19 @@ holding contextual information."
 
 ;;;; Quote Block
 
-(defun org-html-quote-block (_quote-block contents _info)
+(defun org-html-quote-block (quote-block contents info)
   "Transcode a QUOTE-BLOCK element from Org to HTML.
 CONTENTS holds the contents of the block.  INFO is a plist
 holding contextual information."
-  (format "<blockquote>\n%s</blockquote>" contents))
+  (let ((attributes (org-export-read-attribute :attr_html quote-block)))
+    (when (org-element-property :name quote-block)
+      (setq attributes (plist-put
+			attributes :id
+			(org-element-property :name quote-block))))
+    (setq attributes (org-html--make-attribute-string attributes))
+    (when (not (equal attributes ""))
+      (setq attributes (concat " " attributes)))
+    (format "<blockquote%s>\n%s</blockquote>" attributes contents)))
 
 ;;;; Section
 
-- 
2.4.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] add html attributes to special blocks.
  2016-03-28 19:06 [PATCH 1/3] add id attribute to example-block on html export John Kitchin
  2016-03-28 19:06 ` [PATCH 2/3] add html attributes to quote-block John Kitchin
@ 2016-03-28 19:06 ` John Kitchin
  2016-03-30 15:03 ` [PATCH 1/3] add id attribute to example-block on html export Nicolas Goaziou
  2 siblings, 0 replies; 7+ messages in thread
From: John Kitchin @ 2016-03-28 19:06 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: John Kitchin

Enables #+attr_html and puts an id in when the special block is named.
---
 lisp/ox-html.el | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 5bdfc14..da67958 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -3209,22 +3209,28 @@ contextual information."
   "Transcode a SPECIAL-BLOCK element from Org to HTML.
 CONTENTS holds the contents of the block.  INFO is a plist
 holding contextual information."
-  (let* ((block-type (org-element-property :type special-block))
-	 (contents (or contents ""))
-	 (html5-fancy (and (org-html--html5-fancy-p info)
-			   (member block-type org-html-html5-elements)))
-	 (attributes (org-export-read-attribute :attr_html special-block)))
+  (let* ((block-type (downcase
+                      (org-element-property :type special-block)))
+         (contents (or contents ""))
+         (html5-fancy (and (org-html-html5-p info)
+                           (plist-get info :html-html5-fancy)
+                           (member block-type org-html-html5-elements)))
+         (attributes (org-export-read-attribute :attr_html special-block)))
     (unless html5-fancy
       (let ((class (plist-get attributes :class)))
-	(setq attributes (plist-put attributes :class
-				    (if class (concat class " " block-type)
-				      block-type)))))
+        (setq attributes (plist-put attributes :class
+                                    (if class (concat class " " block-type)
+                                      block-type)))
+        (when (org-element-property :name special-block)
+          (setq attributes (plist-put
+                            attributes :id
+                            (org-element-property :name special-block))))))
     (setq attributes (org-html--make-attribute-string attributes))
     (when (not (equal attributes ""))
       (setq attributes (concat " " attributes)))
     (if html5-fancy
-	(format "<%s%s>\n%s</%s>" block-type attributes
-		contents block-type)
+        (format "<%s%s>\n%s</%s>" block-type attributes
+                contents block-type)
       (format "<div%s>\n%s\n</div>" attributes contents))))
 
 ;;;; Src Block
-- 
2.4.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] add id attribute to example-block on html export.
  2016-03-28 19:06 [PATCH 1/3] add id attribute to example-block on html export John Kitchin
  2016-03-28 19:06 ` [PATCH 2/3] add html attributes to quote-block John Kitchin
  2016-03-28 19:06 ` [PATCH 3/3] add html attributes to special blocks John Kitchin
@ 2016-03-30 15:03 ` Nicolas Goaziou
  2016-03-31 20:58   ` John Kitchin
  2 siblings, 1 reply; 7+ messages in thread
From: Nicolas Goaziou @ 2016-03-30 15:03 UTC (permalink / raw)
  To: John Kitchin; +Cc: emacs-orgmode

Hello,

John Kitchin <jkitchin@andrew.cmu.edu> writes:

> This allows you to hyperlink to the block.

Applied the 3 patches, with minor changes (you seem to be using an
outdated Org so you were reverting changes made to master).

Could you provide an ORG-NEWS entry for this?

Thank you.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] add id attribute to example-block on html export.
  2016-03-30 15:03 ` [PATCH 1/3] add id attribute to example-block on html export Nicolas Goaziou
@ 2016-03-31 20:58   ` John Kitchin
  2016-04-02  8:45     ` Nicolas Goaziou
  0 siblings, 1 reply; 7+ messages in thread
From: John Kitchin @ 2016-03-31 20:58 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode

I am not sure what those should look like or where they go. How about:

* New html id attributes on special, example and quote blocks
 If the block has a #+name: attribute assigned, then the html element
 will have an id attribute with that name in the html export. This
 enables one to create links to these elements in other places,
 e.g. <a href="#name">text</a>


Nicolas Goaziou writes:

> Hello,
>
> John Kitchin <jkitchin@andrew.cmu.edu> writes:
>
>> This allows you to hyperlink to the block.
>
> Applied the 3 patches, with minor changes (you seem to be using an
> outdated Org so you were reverting changes made to master).
>
> Could you provide an ORG-NEWS entry for this?
>
> Thank you.
>
> Regards,


--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] add id attribute to example-block on html export.
  2016-03-31 20:58   ` John Kitchin
@ 2016-04-02  8:45     ` Nicolas Goaziou
  2016-04-04  0:31       ` John Kitchin
  0 siblings, 1 reply; 7+ messages in thread
From: Nicolas Goaziou @ 2016-04-02  8:45 UTC (permalink / raw)
  To: John Kitchin; +Cc: emacs-orgmode

Hello,

John Kitchin <jkitchin@andrew.cmu.edu> writes:

> I am not sure what those should look like or where they go. How about:
>
> * New html id attributes on special, example and quote blocks
>  If the block has a #+name: attribute assigned, then the html element
>  will have an id attribute with that name in the html export. This
>  enables one to create links to these elements in other places,
>  e.g. <a href="#name">text</a>

I added this into ORG-NEWS file, in "New features" section.

Thank you.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] add id attribute to example-block on html export.
  2016-04-02  8:45     ` Nicolas Goaziou
@ 2016-04-04  0:31       ` John Kitchin
  0 siblings, 0 replies; 7+ messages in thread
From: John Kitchin @ 2016-04-04  0:31 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode

Thanks. I found this in etc/ORG-NEWS, in case any one else was looking
for it ;)

Nicolas Goaziou writes:

> Hello,
>
> John Kitchin <jkitchin@andrew.cmu.edu> writes:
>
>> I am not sure what those should look like or where they go. How about:
>>
>> * New html id attributes on special, example and quote blocks
>>  If the block has a #+name: attribute assigned, then the html element
>>  will have an id attribute with that name in the html export. This
>>  enables one to create links to these elements in other places,
>>  e.g. <a href="#name">text</a>
>
> I added this into ORG-NEWS file, in "New features" section.
>
> Thank you.
>
> Regards,


--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-04-04  0:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-28 19:06 [PATCH 1/3] add id attribute to example-block on html export John Kitchin
2016-03-28 19:06 ` [PATCH 2/3] add html attributes to quote-block John Kitchin
2016-03-28 19:06 ` [PATCH 3/3] add html attributes to special blocks John Kitchin
2016-03-30 15:03 ` [PATCH 1/3] add id attribute to example-block on html export Nicolas Goaziou
2016-03-31 20:58   ` John Kitchin
2016-04-02  8:45     ` Nicolas Goaziou
2016-04-04  0:31       ` John Kitchin

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).