2013-02-04 45 views
5

मैं Emacs ऑर्ग मोड फ़ाइल में html में absoluted चित्र url निर्यात करने के लिए की जरूरत हैकैसे निर्यात छवि के ओआरजी मोड छवि पूर्ण पथ के लिए?</p> <p>जब मैं निम्नलिखित कोड लिखने:</p> <pre><code>[[file:/images/a.jgp]] </code></pre> <p>एचटीएमएल कोड के निर्यात है:

<img src="file:///images/a.jpg" > 

लेकिन जो मुझे चाहिए:

<img src="/images/a.jgp"> 

तो मैं जो चाहता हूं उसे निर्यात कैसे कर सकता हूं एड, #+BEGIN_HTML टैग का उपयोग करने के बजाय?

पुनश्च: मेरी Emacs config:

16 ;; org-mode project define 
17 (setq org-publish-project-alist 
18  '(
19   ("org-blog-content" 
20   ;; Path to your org files. 
21   :base-directory "~/ChinaXing.org/org/" 
22   :base-extension "org" 
23 
24   ;; Path to your jekyll project. 
25   :publishing-directory "~/ChinaXing.org/jekyll/" 
26   :recursive t 
27   :publishing-function org-publish-org-to-html 
28   :headline-levels 4 
29   :html-extension "html" 
30   :table-of-contents t 
31   :body-only t ;; Only export section between <body></body> 
32   ) 
33 
34   ("org-blog-static" 
35   :base-directory "~/ChinaXing.org/org/" 
36   :base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|swf\\|php\\|svg" 
37   :publishing-directory "~/ChinaXing.org/jekyll/" 
38   :recursive t 
39   :publishing-function org-publish-attachment) 
40   ("blog" :components ("org-blog-content" "org-blog-static")) 
41  )) 

उत्तर

9

तरीका यह है ऑर्ग मोड में लिंक एक नई तरह की रजिस्टर करने के लिए, org-add-link-type का उपयोग कर रहा है। इससे आपको एक कस्टम निर्यात प्रारूप की सुविधा मिलती है।

org-add-link-type एक उपसर्ग की आवश्यकता है, "जब आप लिंक पर क्लिक करते हैं तो क्या होता है?" समारोह, और एक निर्यात समारोह।

मैं img का उपसर्ग का उपयोग करता हूं, इसलिए मेरे लिंक [[img:logo.png][Logo]] जैसा दिखते हैं। मेरी छवि फ़ाइलें ../images/ (.org फ़ाइलों के सापेक्ष) में हैं, और वेबसर्वर से वे /images/ में दिखाई देते हैं। तो उन सेटिंग के लिए, .emacs में इस डाल समाधान प्रदान करता है:

(defun org-custom-link-img-follow (path) 
    (org-open-file-with-emacs 
    (format "../images/%s" path))) 

(defun org-custom-link-img-export (path desc format) 
    (cond 
    ((eq format 'html) 
    (format "<img src=\"/images/%s\" alt=\"%s\"/>" path desc)))) 

(org-add-link-type "img" 'org-custom-link-img-follow 'org-custom-link-img-export) 

आप शायद अपने स्थापना के लिए पथ में संशोधन करने की आवश्यकता होगी, लेकिन यह नुस्खा है। जैसा कि आप उम्मीद करेंगे, सी-एचएफorg-add-link-type आपको पूर्ण विवरण विवरण देगा।

ओह, और इसके लायक होने के लिए, यह कोड मैं इंटर-पोस्ट लिंक (जैसे [[post:otherfile.org][Other File]]) के लिए उपयोग कर रहा हूं। आउटपुट प्रारूप में थोड़ा जैकिल जादू है, इसलिए डबल-% एस देखें।

(defun org-custom-link-post-follow (path) 
    (org-open-file-with-emacs path)) 

(defun org-custom-link-post-export (path desc format) 
    (cond 
    ((eq format 'html) 
    (format "<a href=\"{%% post_url %s %%}\">%s</a>" path desc)))) 

(org-add-link-type "post" 'org-custom-link-post-follow 'org-custom-link-post-export) 
+0

मैं आईमेज-मोड का उपयोग करना चाहता हूं, यह विधि इसका समर्थन नहीं करेगी? कैसे ? – Chinaxing

+0

यह उत्कृष्ट है, धन्यवाद। क्या आप जानते हैं कि मैं 'आईजीजी:' लिंक प्रकार का उपयोग 'org-redisplay-inline-images' के साथ इनलाइन छवियों में emacs कैसे प्राप्त कर सकता हूं? –

+0

एक नोट: ऑर्ग-मोड v 9. ओआरजी-एड-लिंक-प्रकार को अप्रचलित के रूप में रिपोर्ट करता है (हालांकि निर्यात अभी भी काम करता है और आवश्यक img src = "/ etc/anImg.png" उत्पन्न करता है)। [ओआरजी मेलिंग सूची] के लिए एक ईमेल (http://lists.gnu.org/archive/html/emacs-orgmode/2017-04/msg00188.html) ने ऑर्ग-मोड संस्करण 9: (ऑर्ग-लिंक-सेट-पैरामीटर "आईएमजी" : 'org-custom-link-img-follow का पालन करें: निर्यात' org-custom-link-img-export) – mzimmermann