Fully self-contained HTML files with Pandoc

SAAD

I have little knowledge in HTML and Javascript, and I want to know the following:

I have a master HTML file which contains some text, images ... and it also contains internal references to other local HTML files, which are put in a relative directory. Is it possible to make a fully self-contained HTML file, where the other files are still referenced by URL links but their content is simply recorded in the master file ?

I had this problem using the --self-contained option in Pandoc, which only writes all the necessary stuff (CSS stylesheet, ...) into the HTML header, while the master HTML document still needs the "see" the actual local files.

So far, I tried the iframe tag, but it is always opened, and is not simple put in a page,like a one-line URL link. I have read this answer using HTML+javascript but I am not sure if this compatible with Pandoc.

Anyone who can help me understand the difficulty of such task ?

mschilli

You could convert your sub HTMLs into Base64 strings and link them using the Data URI scheme in your main HTML:

  1. Create your sub HTML file:
<!-- sub.html -->
<html>
 <head>
  <title>
   Sub HTML
  </title>
 </head>
<body>
 <h1>Sub HTML</h1>
 <p>This is the Sub HTML.</p>
</body>
</html>
  1. Convert its file content to Base64 (e.g. using base64encode.org):

PCEtLSBzdWIuaHRtbCAtLT4NCjxodG1sPg0KIDxoZWFkPg0KICA8dGl0bGU+DQogICBTdWIgSFRNTA0KICA8L3RpdGxlPg0KIDwvaGVhZD4NCjxib2R5Pg0KIDxoMT5TdWIgSFRNTDwvaDE+DQogPHA+VGhpcyBpcyB0aGUgU3ViIEhUTUwuPC9wPg0KPC9ib2R5Pg0KPC9odG1sPg==

  1. Create your main HTML linking the sub HTML by a Data URI with the Base64 encoding of the target file:
<!-- main.html -->
<html>
 <head>
  <title>
   Main HTML
  </title>
 </head>
<body>
 <h1>Main HTML</h1>
 <p> This is the Main HTML. </p>
 <p>
  <a href="sub.html">
    This link to the sub HTML
  </a>
  references the target by its (relative) path and won't work without the
  2nd file.
  <br>
  <a href="data:text/html
          ;UFT8
          ;base64,PCEtLSBzdWIuaHRtbCAtLT4NCjxodG1sPg0KIDxoZWFkPg0KICA8dGl0b
                  GU+DQogICBTdWIgSFRNTA0KICA8L3RpdGxlPg0KIDwvaGVhZD4NCjxib2
                  R5Pg0KIDxoMT5TdWIgSFRNTDwvaDE+DQogPHA+VGhpcyBpcyB0aGUgU3V
                  iIEhUTUwuPC9wPg0KPC9ib2R5Pg0KPC9odG1sPg==
          ">
    This link to the sub HTML
  </a>
  references the target by its Base64 encoding and will work without the
  2nd file.
 </p>
</body>
</html>

edit:

Since the question was specifically asked about pandoc, here is the above example using Markdown:

  1. Create your sub Markdown file:
# Sub HTML

This is the sub HTML.
  1. Convert your sub Markdown file to HTML using pandoc:
pandoc sub.md > sub.html
  1. Convert your sub HTML file to Base64:
base64 < sub.html

PGgxIGlkPSJzdWItaHRtbCI+U3ViIEhUTUw8L2gxPgo8cD5UaGlzIGlzIHRoZSBzdWIgSFRNTC48 L3A+Cg==

  1. Create your main Markdown file referencing the sub HTML file by a Data URI:
# Main HTML

This is the main HTML.

[This link to the sub HTML][relative_path] references the target by its
(relative) path and won't work without the 2nd file.
[This link to the sub HTML][data_uri] references the target by its Base64
encoding and will work without the 2nd file.

[relative_path]: sub.html
[data_uri]: data:text/html;ASCII-US;base64,PGgxIGlkPSJzdWItaHRtbCI+U3ViIEhU
TUw8L2gxPgo8cD5UaGlzIGlzIHRoZSBzdWIgSFRNTC48L3A+Cg==
  1. Convert your main Markdown file to HTML using pandoc:
pandoc main.md > main.html

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Fully self-contained HTML files with Pandoc

From Dev

Is it possible to create a fully self-contained Python package?

From Dev

Is a Preloader needed for an fully self-contained Flash SWF application?

From Dev

Backup mysql databases into self contained files

From Dev

Pandoc - Export to multiple HTML files

From Dev

Self contained login using HTML and/or Javascript

From Dev

Self contained login using HTML and/or Javascript

From Dev

Building a self-contained binary executable in Haskell with the dependency pandoc-citeproc

From Dev

Input not being fully contained by parent

From Dev

Input not being fully contained by parent

From Dev

Self Contained WPF .net

From Dev

Issues converting larger HTML files to docx in pypandoc (pandoc)

From Dev

Self-Contained .Net Core Library missing .NET Core Runtime files

From Dev

Mimic R CMD build HTML vignette: Embed external images as self contained

From Dev

Creating a self contained, offline HTML5 app and the best method for embedding its resources

From Dev

Creating a self contained, offline HTML5 app and the best method for embedding its resources

From Dev

Spring Boot/Angular app. routing a completely self contained HTML file

From Dev

Self-contained generic memento

From Dev

Self-contained shared library

From Dev

Self-Contained Linked List

From Dev

Snappy and self-contained programs

From Dev

Pandoc: escape HTML option

From Dev

Selenium not fully downloading files

From Dev

How can I disable the highlighting of HTML contained in .js/.ts files in Webstorm?

From Dev

Pandoc - Insert separator between files

From Dev

Batch convert files with pandoc in windows

From Dev

Pandoc - Insert separator between files

From Dev

How to process multiple files with pandoc?

From Dev

A web crawler in a self-contained python file

Related Related

  1. 1

    Fully self-contained HTML files with Pandoc

  2. 2

    Is it possible to create a fully self-contained Python package?

  3. 3

    Is a Preloader needed for an fully self-contained Flash SWF application?

  4. 4

    Backup mysql databases into self contained files

  5. 5

    Pandoc - Export to multiple HTML files

  6. 6

    Self contained login using HTML and/or Javascript

  7. 7

    Self contained login using HTML and/or Javascript

  8. 8

    Building a self-contained binary executable in Haskell with the dependency pandoc-citeproc

  9. 9

    Input not being fully contained by parent

  10. 10

    Input not being fully contained by parent

  11. 11

    Self Contained WPF .net

  12. 12

    Issues converting larger HTML files to docx in pypandoc (pandoc)

  13. 13

    Self-Contained .Net Core Library missing .NET Core Runtime files

  14. 14

    Mimic R CMD build HTML vignette: Embed external images as self contained

  15. 15

    Creating a self contained, offline HTML5 app and the best method for embedding its resources

  16. 16

    Creating a self contained, offline HTML5 app and the best method for embedding its resources

  17. 17

    Spring Boot/Angular app. routing a completely self contained HTML file

  18. 18

    Self-contained generic memento

  19. 19

    Self-contained shared library

  20. 20

    Self-Contained Linked List

  21. 21

    Snappy and self-contained programs

  22. 22

    Pandoc: escape HTML option

  23. 23

    Selenium not fully downloading files

  24. 24

    How can I disable the highlighting of HTML contained in .js/.ts files in Webstorm?

  25. 25

    Pandoc - Insert separator between files

  26. 26

    Batch convert files with pandoc in windows

  27. 27

    Pandoc - Insert separator between files

  28. 28

    How to process multiple files with pandoc?

  29. 29

    A web crawler in a self-contained python file

HotTag

Archive