XHTML / JSF boilerplate code in Emacs - emacs

I am using Emacs to write XHTML pages in a JSF project and the amount of boilerplate code that has to go at the header of each XHTML file is hard-to-type, ugly and error-prone. E.g:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
What would be the "emacs way" of dealing with this? I 've read about the nXhtml mode but haven't tried it and don't know if it auto-completes boilerplate like the above or just offers more rudimentary XML checking / completion syntax. At any rate I would like to evaluate more lightweight alternatives first.

search for "template emacs". https://www.google.com/search?q=template+engine+emacs
here's a good survey: http://www.emacswiki.org/emacs/CategoryTemplates .
I use defaultcontent.el, which is one of the options listed on that page. Defaultcontent.el fills new files with a template depending on a pattern match on the filename. All .html files can get a particular template. You can do more advanced mapping of templates to files; defaultcontent.el uses an alist and you can specify any regex for the filename you like.
The template that gets placed into the new file can expand various things dynamically, including the filename, basefilename, date/time, environment variables. In more advanced scenarios the template can run elisp code that you provide.
It's a good companion to yasnippet, which I use for optional pieces of code within a file. For example, my base .htm template (inserted by defaultcontent.el) doesn't include a script reference for jquery. But I have a yasnippet for jquery , so that when I type (jquery[TAB]), I get the full expansion of
<script type='text/javascript'
src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js'>
</script>
defaultcontent.el uses find-file-hooks and inserts template contents only when a file is initially created.
I use it for virtually all file formats.

Related

Cannot export org mode to collapsible HTML

I am trying to have basic collapsing/folding functionality for sections in the HTML file that has been exported from org-mode, since the files I want to share are very large. I am using Emacs 26.2 (9.0) and Org 9.1.9 on a Mac.
This seems like a built in feature, but I haven't seen any effect from adding #+INFOJS_OPT commands to my org files before exporting to HTML. I also saw another tool mentioned on the mailing lists, but without any examples I don't know how apply it to a specific org file I have.
For example, the following file is converted to HTML which looks identical to the same file without the INFOJS_OPT lines
#+Title+: JS test
#+INFOJS_OPT: path:js/org-info.js
#+INFOJS_OPT: toc:nil ltoc:nil view:overview mouse:underline
#+INFOJS_OPT: home:https://orgmode.org buttons:nil
* Chapter 1
** Section 1
*** Part 1
- csp
** Section 2
- cs2p
I have a freshly-downloaded copy of js/org-info.js.
There is a slight difference in the HTML generated, but this seems to have no effect. I'm at a loss for how I can have folding in the resulting HTML - open to solutions even outside of org-info.js.
Seems that org-info.js is not maintained anymore. Here they provide the source code in JavaScript, for anyone willing to tweak/update it.
https://lists.gnu.org/r/emacs-orgmode/2017-07/msg00049.html
Luckily someone updated it (thanks Daniel Clemente!).
The procedure is:
Download esquemadorg.js at the following link: https://www.danielclemente.com/pagina/esquemadorg.js
Add the following lines at the top of your .org file
#+HTML_HEAD_EXTRA: <script type="text/javascript" src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
#+HTML_HEAD_EXTRA: <script type="text/javascript" src="esquemadorg.js"></script>
Make sure that src="esquemadorg.js" points at the file relative to where the html exported file is located.
Some text in Spanish (or Portuguese?) will appear on the exported document. You can do a full search in the esquemadorg.js file and change it to English. Mine looks like this now.
par.append(document.createTextNode("Press on a section header to collaps/expand it."));
par.append( $( document.createElement('a') ).text(" COLLAPSE ALL ").addClass("globalexpandtool").click(close_all_sections));
par.append( $( document.createElement('a') ).text(" SHOW ALL ").addClass("globalexpandtool").click(open_all_sections));
$("div#table-of-contents").after(par);

How can I get github to display inline math in README.org file

I have tried numerous HTML preambles such as the following minimal example:
#+TITLE: Some math stuff
#+BEGIN_HTML
<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
#+END_HTML
=(solve a b)= should return $X$, from $AX=B$
The inline math works on my desktop if I export to HTML and view in my browser, but does not seem to be rendered in Github where the dollar signs are just echoed in the output.
Any idea on how to get Github to render inline math? Please note the answer to this question on how to do the same with README.md doesn't help as markdown is dissimilar to the much more featureful org mode.
EDIT: I have now learned how Github processes the .org file using github/markup which in turn uses org-ruby to parse the file. It appears that code blocks with #+BeginSrc etc are parsed very well but not the preamble lines or the inline math---though I have not really confirmed this yet.
#david This is the partial but hopefully relevant source from my webpage:
README.org
<article class="markdown-body entry-content" itemprop="mainContentOfPage"><h1><a id="user-content-some-math-stuff" class="anchor" href="#some-math-stuff" aria-hidden="true"><span class="octicon octicon-link"></span></a>Some math stuff</h1>
<p><code>(solve a b)</code> should return $X$, from $AX=B$</p>
</article>
</div>
Edit 2:
Signal for #VonC in the comments: GitHub supports Latex/MathJax since May 2022
https://github.com/github/markup/issues/274 seems to indicate that it's not currently possible. The issue was closed with no resolution.

How to set a favicon for Doxygen output

I am automating documentation generation using Doxygen. How can I specify a favicon (URL icon) for the output?
In doxygen one has the possibility to define his own HTML header file, best based on the default HTML header file.
To obtain the default HTML header file, syntax:
doxygen -w html headerFile footerFile styleSheetFile [configFile]
in the headerFile insert in the head part a line like:
<link rel="shortcut icon" href="$relpath^my_icon.ico" type="image/x-icon" />
Note: that the $relpath^ part is necessary especially in case of CREATE_SUBDIRS is set.
Furthermore in the configuration file (Doxyfile) you have to set:
HTML_HEADER = headerFile
HTML_EXTRA_FILES += my_icon.ico
Of course the standard restrictions regarding favicons still apply (regarding support by browsers etc.).

Can I embed a custom title in a perlpod document?

When writing perlpod documentation that will be exported to HTML, can I embed the title of the resulting HTML file in the POD directives?
I want to be able to convert multiple POD text files to HTML with the pod2html command, and don't want to have to give the --title="My Title" parameter on the command-line.
For example, here is a text file with perlpod formatting:
=pod
=head1 This is a heading
This is some text. I'd like to set the title of this document in the resulting HTML file.
=cut
When I convert it to HTML, pod2html gives a warning about there being no title:
$ pod2html test.txt > test.html
/usr/bin/pod2html: no title for test.txt
In the resulting HTML file, the title is set to the filename (test.txt):
<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>test.txt</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:root#localhost" />
</head>
<body style="background-color: white">
<p><a name="__index__"></a></p>
<!-- INDEX BEGIN -->
<ul>
<li>This is a heading.</li>
</ul>
<!-- INDEX END -->
<hr />
<p>
</p>
<hr />
<h1><a name="this_is_a_heading_">This is a heading.</a></h1>
<p>This is some text. I'd like to set the title of this document.</p>
</body>
</html>
I'd like to find a way to have the title given in the perpod document, perhaps with a directive like this:
=title This is my custom title
In the Perl documentation, I see that the document titles are set nicely. Is this all done without having the document title in the pod document itself?
There is nothing in the Pod documentation that controls the title of the document. This up to the program that converts the Pod documentation to the format you want. Most of the pod2doc programs that you use to generate the documentation will have a module like Pod::Text or Pod::Html. These do most of the grunt work in converting.
pod2html takes a --title parameter. However, what you want is for pod2html to do it without you having to specify it. What you can do is roll your own version of pod2html. Let's look at pod2html script itself, and maybe you can figure out what you can do to get what you want.
Removing all the POD document, I see::
use Pod::Html
pod2html #ARGV
That's the entire program.
It looks like you could make a pod2steve program to do what you want. You want to take the last parameter (which I assume is what you want the title to be), and simply pass it through the pod2html subroutine. Your pod2steve would look something like this:
use strict;
use warnings;
use Pod::Html
my $program_name = $ARGV[$#ARGV];
pod2html --title=$program_name #ARGV
That should work.
No.
POD exists mainly¹ to write Perl module documentation², and therefore doesn't have many fancy features. Also, the primary output medium for POD is the terminal, where no such thing as a title exists conceptially³. It is, after all, just Plain and Old documentation.
    1. Suprisingly many Perl books are written in POD.
    2. The location of the POD document coincides with the thing discussed in the text.
    3. The ps name / $0 variable comes close, but is useless here.
This is also a technical problem: pod2html uses Pod::Html, which parses the command line, and wraps itself around Pod::Simple::XHTML or something, without doing, or interfering with, the actual parsing. However, it already supplies a header and a footer, which sensibly overrides any default headers that might be emitted.
There are two interesting options how your problem can be solved:
You write a postprocessor that puts the value of the first h1 into the title. This should be <10 lines in a parser with XPath-support. Then you write a little script that ties these together, and can be invoked instead of pod2html.
You take the existing wealth of POD parsers (and source code), and whip up your own HTML from POD generator. If all you are actually doing is a small fork, you could try to offer the modification to the original module.

Including literal HTML code in org-mode templates

In org-mode, when you export HTML projects you can use templates to give all exported pages the same options, this is described here http://orgmode.org/worg/org-tutorials/org-publish-html-tutorial.html. What I would like to do, is give all exported pages an HTML snippet, for analytics, which is not an option. Is this possible with org-templates?
Now, I tried to add literal HTML code to the base template level-0-template.org with
#begin_html
...
#end_html
but it didn't work out. Does anyone know how to add html code to each HTML file that is exported in the project?
My project is organized as follows:
|- org
|- index.org
|- html
|- index.html (this is exported)
|- templates
|- level-0.org (I'd like to include default html here)
|- org_publish.el (this is the publishing config file)
To expand on my comment in the question, here is the difference between #+setupfile: and #+include:.
Details about both are available in the Org-Mode manual. See Setup File and Include Files.
The setupfile is essentially a list of all org configurations that are included in the linked file. It will pass things such as #+options. It will not however include any other content that the original file might include.
On the other hand, #+include: inserts the content of the linked file wherever the line is inserted. It acts similarly to \input in LaTex. I'm not certain to what degree it will bring along any org-configuration settings from the linked file, you may need to both #+include and #+setupfile the file to ensure everything is present. However since you do want the body content of the file to be included in each, you have to use #+include to insert it.
Glad you found a solution to your problem by sourcing your snippet as a separate html file.
If you wanted to make it work by having the snippet directly included in your template file, you should use:
#+BEGIN_export html
...
#+END_export
instead of:
#+BEGIN_html
...
#+END_html
(The latter will embed the html chunk as a block in the rendered html page-not what you want; the former will export the html chunk as is in the html file so that that code will be rendered when the page is displayed-what you want).