Date: 2015jan26
Update: 2025oct1
Language: Java
Q. Java: What's a nice way to make a heading in the Markdown language?
A. Here is a full example:
class Demo {
static void putHeading(final String txt) {
System.out.println(txt);
System.out.println(txt.replaceAll(".","="));
}
static void putSubHeading(final String txt) {
System.out.println(txt);
System.out.println(txt.replaceAll(".","-"));
}
public static final void main(String []args) {
putHeading("This is the Heading");
System.out.println("Some words go here");
System.out.println();
putSubHeading("This is the SubHeading");
System.out.println("Other words go here");
System.out.println();
}
}
Output:
This is the Heading
===================
Some words go here
This is the SubHeading
----------------------
Other words go here
To show that's valid markdown I ran that thru pandoc:
pandoc < test.md
<h1 id="this-is-the-heading">This is the Heading</h1>
<p>Some words go here</p>
<h2 id="this-is-the-subheading">This is the SubHeading</h2>
<p>Other words go here</p>
This works by turning every character in the heading to an equals (=).
It uses the regular expression dot (.) which matches every character.
The original string is not damaged.
More info
http://en.wikipedia.org/wiki/Markdown