LXer now speaks Markdown
What changedEvery place on LXer where you write more than a line now has a Markdown editor:
You type plain text, and a few marks such as asterisks, pound signs and backticks say how it should look. A toolbar above the text box inserts the marks for you, so you never have to remember them. Two buttons are worth knowing about: the eye shows the post exactly as it will be published, and the split-screen button shows your text and the result side by side as you type. The first reactions from members have been positive. Thank you to everyone who tried it early and told us what worked and what did not. Writing a postHere is a short forum post as you would type it:
That gives you a heading, bold text, a numbered list, a bit of code, a quotation and a link, and the text is still easy to read before it is formatted. That is the whole idea of Markdown. The marks you will use most often:
A web address on its own line becomes a link by itself. Three backticks on their own lines around a block of text keep it exactly as typed, which is what you want for commands, configuration files and log output. One thing works differently on LXer than on many other Markdown sites: pressing Enter starts a new line. A blank line starts a new paragraph. We heard early on that people expected their line breaks to stay where they put them, so they do. Tables, footnotes and mathTables are drawn with Footnotes keep a source or an aside out of the way of the text.1 They are collected at the end of the post. This is a Linux site, and some of our readers write about algorithms, signal processing and cryptography, so the editor also understands LaTeX math. Put a formula between dollar signs for inline math, such as
which comes out as \sum_{k=1}^{n} k = \frac{n(n+1)}{2} Prices are safe: "it costs $5 or $10" stays plain text. A formula has to start right after its opening dollar sign and end right before its closing one, and a dollar sign followed directly by a digit never closes a formula. Pictures, links and safetyEditors can place pictures in stories. In members' posts, an image is shown as a link to the picture instead, so nobody can slip a tracking pixel or a hotlinked image into a forum thread. Links in members' posts carry the usual Anything that looks like HTML is shown exactly as typed and never run. If you want to explain the Older postsTwo decades of LXer posts were written with BBCode-style tags and bits of HTML. They look exactly as they always did. When you edit an old post, it stays in its old format; only new posts are Markdown. Help is one click awayEvery editor has a ? button on its toolbar, and a "Formatting help" link below it. Both open a cheat sheet with examples of everything above, shown side by side as you type them and as they come out. The cheat sheet is also its own page: Markdown help. Sixty years of writing in plain textMarkdown did not come out of nowhere. People have been putting formatting instructions into plain text for as long as computers have printed documents, and almost every idea in Markdown was tried somewhere first. RUNOFF and roff: commands in the marginIn 1964 Jerome Saltzer wrote RUNOFF for CTSS, the time-sharing system at MIT. A line that started with a period was a command: RUNOFF's descendant roff had an important role in the history of Unix. Around 1970, the Bell Labs team behind Unix got a PDP-11 by promising the patent department a system for preparing patent applications. The text formatter that ran on it was roff. Joe Ossanna's nroff and troff followed, for terminals and for the phototypesetter, and the Unix manual itself was typeset with them. You still use roff every day. Type TeX and LaTeX: where our dollar signs come fromIn the late 1970s Donald Knuth was unhappy with how the new edition of The Art of Computer Programming was being typeset, so he wrote his own typesetting system, TeX. Leslie Lamport's LaTeX macros made it practical for everyday papers in the early 1980s, and it is still the standard in mathematics and physics. TeX put math between dollar signs. That is why GML, SGML and HTML: tagsAt IBM in 1969, Charles Goldfarb, Edward Mosher and Raymond Lorie designed the Generalized Markup Language. GML described what a piece of text was, a heading or a list item, not how it should look. GML grew into SGML, an ISO standard in 1986, and in 1991 Tim Berners-Lee at CERN used SGML's angle-bracket tags for a small language called HTML. HTML is precise, but it is tiring to write by hand, and letting visitors type it into a web form is dangerous. That problem shaped everything that came next. Email, setext, wikis and BBCodeMeanwhile, people writing email and Usenet posts had settled on their own conventions: Around 1992 Ian Feldman created setext for the TidBITS newsletter, which was distributed as plain text. A title was underlined with a row of In 1995 Ward Cunningham opened the first wiki, the WikiWikiWeb, where anyone could edit any page in their browser. Wiki markup used doubled apostrophes for italics and ran words together into links. Wikipedia's markup descends from it. Web forums needed a way to let visitors format posts without letting them write raw HTML. In 1998 the Ultimate Bulletin Board introduced BBCode: 2002: Textile, reStructuredText and atxBy 2002 several people were trying to design a markup that was easy to type and easy to read. Dean Allen released Textile for his blogging tool. David Goodger's reStructuredText became the documentation format of the Python world. The Linux kernel also adopted it: since version 4.8 in 2016, the kernel's documentation has been written in reStructuredText and built with Sphinx. That same year Aaron Swartz published atx, a small format with headings marked by 2004: MarkdownIn 2004 John Gruber released Markdown, a Perl script that turned plain text into HTML, with Aaron Swartz as his main collaborator on the syntax. The name was a play on "markup". The guiding rule was set out in Gruber's syntax description:
Markdown borrowed openly from what came before. Gruber's own documentation calls the two heading styles "atx-style" and "Setext-style". The email conventions for emphasis and quoting came along almost unchanged. Aaron Swartz had already helped write the RSS 1.0 specification as a teenager. He went on to co-found Reddit and to campaign for an open Internet, and he died in January 2013 at the age of 26. Success, and a specificationMarkdown spread from blogs to Stack Overflow, which adopted it in 2008, and then to GitHub, where a Success brought a problem. Gruber's description was short and friendly, but it left many cases open. What happens to a list right after a paragraph? How many spaces indent a sub-list? Every program answered differently. John MacFarlane, a philosophy professor at UC Berkeley and the author of the document converter Pandoc, built a tool called Babelmark that sends the same text to dozens of Markdown programs. It showed how often they disagreed. In 2014 MacFarlane, Jeff Atwood of Stack Overflow and others published a precise specification with hundreds of test cases. They first called it "Standard Markdown". Gruber objected to the name, so they renamed it CommonMark. In 2017 GitHub based its own dialect, GitHub Flavored Markdown, on CommonMark and added tables, strikethrough and automatic links. GitHub added LXer follows the same path: CommonMark, plus GitHub's tables, strikethrough and automatic links, plus footnotes and math. Under the hoodFor readers who like to know what runs their software:
Tell us what you thinkThe best way to learn Markdown is to try it: open the forums, start a reply, and press the eye button to see the result before you post. If something does not look the way you expected, or there is a feature you miss, post a comment below. This comment box uses Markdown too.
|
Comments (8)
Someone call a debugger, we've got a math professor in the comments! 🤓 All those \sum symbols and limits... are you trying to calculate the efficiency of the post or just trying to make my brain crash? Go touch some actual grass (and not just the ~/grass directory)!
But hey, since we're all playing with the new toys, I might as well use them.
The Plain Text Way
A kernel robust, a penguin so bold,
In stories of Linux, the legends are told.
No more heavy tags, no more HTML mess,
Just Markdown and magic, we must all confess.With
*asterisks*and**bold**to play,
LXer shines brighter in a brand new way.
From thebashcommand to the math in our heart,
It's a beautiful, plain-text, open-source art.
Love the new update! 🐧✨
tuxgirl wrote:
are you trying to calculate the efficiency of the post or just trying to make my brain crash?
Um... yes?
tuxgirl wrote:
Love the new update! 🐧✨
Very cool. Where did you get those emojis?
@penguinist
There is a "Symbols and emoji" icon on the editor toolbar. It looks like \Omega. Click on that and the Tux icon is first in the list (of course it is first).
Ok, since we are playing with this new toy, let's try this with some code. Here is something fun, a mandelbrot set with an interesting end point.
Copy this code to a file like mandel.py and run it with python mandel.py. Have fun!
🐍 PythonPete 🐍
import time
import sys
def mandelbrot_zoom(total_frames):
chars = "@#W$9876543210?!abcdeFGABCDE"
center = complex(-0.743643887, 0.1318259)
scale, max_iter = 2.0, 50
try:
# The loop runs for a fixed number of iterations provided by the user
for frame in range(total_frames):
sys.stdout.write("\033[H\033[J")
lines = []
for y in range(40):
im = center.imag + (y/40 - 0.5) * scale
row = ""
for x in range(80):
re = center.real + (x/80 - 0.5) * scale * 2.0
c, z, n = complex(re, im), 0j, 0
while abs(z) <= 2 and n < max_iter:
z = z*z + c
n += 1
idx = int((n / max_iter) * (len(chars) - 1))
row += chars[idx]
lines.append(row)
sys.stdout.write(f"Frame: {frame+1}/{total_frames}\n" + "\n".join(lines) + "\n")
sys.stdout.flush()
scale *= 0.98
time.sleep(0.03)
print("\n[!] Sequence complete. Zoom finished.")
except KeyboardInterrupt:
print("\n[!] Zoom halted by user (Ctrl+C).")
if __name__ == "__main__":
# Use the first command line argument as the number of frames.
# Default to 300 if no argument is provided.
try:
frames_to_run = int(sys.argv[1]) if len(sys.argv) > 1 else 300
mandelbrot_zoom(frames_to_run)
except ValueError:
print("Usage: python mandel.py [number_of_frames]")
PythonPete wrote:
Here is something fun, a mandelbrot set with an interesting end point.
I ran it and it was fun, but I'd like to see that implemented in full graphics and with an infinite depth while staying centered on an edge.
tuxgirl wrote:
I ran it and it was fun, but I'd like to see that implemented in full graphics and with an infinite depth while staying centered on an edge.
I'll accept that challenge tuxgirl. Yes, it’s possible to do what you ask. Here is mandel_deep.py with 74 lines, uses only numpy and pygame, and opens a full-color window that zooms with no end. Run it with python mandel_deep.py [speed] where speed defaults to 0.03 (the \log_2 of zoom per frame). Esc quits or just close the window.
#!/usr/bin/env python3
"""Endless Mandelbrot zoom, in a window, into a point that lies exactly on the boundary.
Usage: python mandel_deep.py [zoom_speed] (Esc or close window to quit; needs numpy, pygame)
The centre is a Misiurewicz point c0: its orbit lands exactly on a repelling cycle, so c0 is on
the boundary and its reference orbit Z_n is known in plain floats forever. The first N
iterations of every pixel are replaced by z_N = Z_N + a_N*dc (a_n = dz_n/dc, kept as
mantissa*2^exponent), so frame cost stays flat while the depth passes 1e-308 and keeps going."""
import sys, math
import numpy as np
import pygame
W, H, EXTRA = 800, 600, 400 # window size, iterations computed after the skip
SPEED = float(sys.argv[1]) if len(sys.argv) > 1 else 0.03 # log2 of zoom per frame
GUESS, PRE, PER = complex(-0.1011, 0.9563), 4, 1 # M(4,1): 3-armed spiral
def misiurewicz(c): # Newton on z_{PRE+PER}(c) - z_PRE(c) = 0
for _ in range(60):
z, dz, zs, dzs = 0j, 0j, [], []
for _ in range(PRE + PER + 1):
zs.append(z); dzs.append(dz)
z, dz = z * z + c, 2 * z * dz + 1
c -= (zs[-1] - zs[PRE]) / (dzs[-1] - dzs[PRE])
return c, zs
def Zn(Z, n): # reference orbit: preperiod, then the cycle forever
return Z[n] if n < PRE else Z[PRE + (n - PRE) % PER]
def skip(t, Z): # largest N with |a_N * 2^-t| < 1e-6, and b = a_N * 2^-t
m, e, n = 0j, 0, 0 # a_n = m * 2^e
while True:
m2 = 2 * Zn(Z, n) * m + 2.0 ** -e
f = math.frexp(abs(m2))[1]
m2, e2 = m2 * 2.0 ** -f, e + f
if abs(m2) * 2.0 ** (e2 - t) > 1e-6:
return n, m * 2.0 ** (e - t)
m, e, n = m2, e2, n + 1
def render(t, c0, Z, w):
N, b = skip(t, Z)
z = (Zn(Z, N) + b * w).ravel()
c = (c0 + 2.0 ** -t * w).ravel() # offset underflows to 0 when deep; harmless by then
idx, mu = np.arange(z.size), np.full(z.size, np.nan)
for k in range(EXTRA):
z = z * z + c
out = z.real * z.real + z.imag * z.imag > 1e6
if out.any(): # smooth (continuous) escape count, then drop escapees
mu[idx[out]] = N + k + 1 - np.log2(np.log(np.abs(z[out])))
idx, z, c = idx[~out], z[~out], c[~out]
if idx.size == 0:
break
x = 2 * np.pi * np.nan_to_num(mu) / 32 # linear in total count: stays continuous as N grows
rgb = 0.5 + 0.5 * np.cos(x[:, None] + np.array([0.0, 2.1, 4.2]))
rgb[np.isnan(mu)] = 0 # never escaped: treat as inside
return N, (255 * rgb).reshape(H, W, 3).astype(np.uint8)
def main():
c0, Z = misiurewicz(GUESS)
y, x = np.mgrid[0.5:-0.5:H * 1j, -W / H / 2:W / H / 2:W * 1j]
w = x + 1j * y # pixel offsets in units of the view height
pygame.init()
screen, clock, t = pygame.display.set_mode((W, H)), pygame.time.Clock(), -math.log2(3)
while True:
for ev in pygame.event.get():
if ev.type == pygame.QUIT or (ev.type == pygame.KEYDOWN and ev.key == pygame.K_ESCAPE):
return pygame.quit()
N, img = render(t, c0, Z, w)
pygame.surfarray.blit_array(screen, img.swapaxes(0, 1))
pygame.display.set_caption(f"Mandelbrot view height 10^-{t * math.log10(2):.1f} skip N={N}")
pygame.display.flip()
t += SPEED
clock.tick(60)
if __name__ == "__main__":
main()
Have fun!
Post a comment
A free account is needed to post. Write your comment here first: your text is kept in this browser while you sign up or log in, and is waiting for you when you come back.
Your message:Sign up and post (it is free) or Log in and post
|
|
As a software engineer, I find the history of markup languages fascinating—it's essentially the evolution of abstraction layers. I've performed a quick "formal verification" of the efficiency gains provided by this update:
Analysis of Syntactic Overhead
If we define E as the cognitive effort required to author a post, and S as the syntactic density (tags per character), we can model the transition from the "Old Regime" (BBCode/HTML) to the "New Regime" (Markdown) as follows:
\lim_{S \to 0} \text{Readability}(E) = \infty
Where the complexity of maintaining a readable plain-text version of the post is minimized. In the old system, the overhead was often non-linear:
E_{\text{BBCode}} \approx \sum_{i=1}^{n} (\text{content}_i + \text{tags}_i) \gg E_{\text{Markdown}}
Comparative Complexity Matrix
Implementation Test Case
I ran a quick check on the parser's ability to handle standard Unix-style input within the new block:
# Testing the integration of Markdown within the LXer ecosystem if [[ "$EDITOR" == "Markdown" ]]; then echo "Efficiency increased." uptime | awk '{print "System Load: " $1}' else echo "Regression detected." fi