Code Monkey home page Code Monkey logo

markdown-content-blocks's Introduction

Version
0.4

John Gruber remarked that image syntax was his biggest mistake with Markdown, and mentioned an alternative:

My best idea for good Markdown img syntax would be to just paste in a URL ending in .jpg/.png/.gif etc.

We liked the idea:

http://example.com/minard.jpg (Napoleon’s disastrous Russian campaign of 1812)
/Flowchart.png "Engineering Flowchart"

At the time, we were also looking for a syntax for file transclusion. The same idea applied equally well to other file types:

/Savings Account.csv 'Recent Transactions'
/Example.swift
/Lorem Ipsum.txt

CSV files are embedded as tables, source code files become code blocks, and embedded text files help writers structure their work:

| Debit | Credit |
|:--|:--|
| 0 | 0 |
[Recent Transactions]

```swift
print("Hello World!")
```

Lorem ipsum dolor sit amet.

We decided to call this syntax “content blocks”. You can try it in iA Writer 4 today.

We think that content blocks are a natural extension of Markdown. We’d be happy if more apps supported them. We’re publishing this spec to aid the process, and to start the conversation around it. We’re just getting started. Your suggestions are welcome.

We describe content block syntax closely following John Gruber’s Markdown Syntax and CommonMark Spec.


A content block consists of:

  • a online image URL, or a local file path, optionally indented by up to three spaces;
  • optionally followed by a title, enclosed in double or single quotes, or enclosed in parentheses, which, if present, must be separated from the URL or path by one or more spaces (or tabs).

An online image URL consists of either:

  • a sequence of zero or more characters between an opening < and a closing > that contains no spaces, line breaks, or unescaped < or > characters, or
  • a nonempty sequence of characters that does not include ASCII space or control characters, and includes parentheses only if (a) they are backslash-escaped or (b) they are part of a balanced pair of unescaped parentheses that is not itself inside a balanced pair of unescaped parentheses

which ends with:

  • a period, followed by one of the following path extensions: png jpg jpeg gif tif tiff svg;
  • optionally followed by a query string starting with ?;
  • optionally followed by a fragment identifier starting with #.

iA Writer automatically uses direct links for images hosted on some services. Currently, it adds raw=1 query item for online image URLs from GitHub and Dropbox.


A local file path consists of one or more path components. Path component consists of:

  • a forward slash /;
  • followed by file name: a sequence of one or more characters including spaces (but not tabs);
  • followed by path extension (optional for all but last path component), which consists of a period, followed by a sequence one or more uppercase or lowercase ASCII characters or numbers.

A content block title consists of either:

  • a sequence of zero or more characters between straight double-quote characters ", including a " character only if it is backslash-escaped, or
  • a sequence of zero or more characters between; straight single-quote characters ', including a ' character only if it is backslash-escaped, or
  • a sequence of zero or more characters between matching parentheses (...), including a ) character only if it is backslash-escaped.

Content block titles block titles have obvious uses for some files, for example image alt attributes and figure captions, table captions. Content block titles are ignored when there’s no obvious use, for example with other plain text files.

Source code path extensions are mapped to programming language names with Languages.json when path extensions are different from lowercased programming language names.

markdown-content-blocks's People

Contributors

antons avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

markdown-content-blocks's Issues

Add classes to content blocks

Is there a way to add a (css) class to a content block? Especially for images. E.g. to create left/right floating images in the document?

More specific definition for online image URLs

Right now the spec says that an online image URL

includes: • a period, followed by one of the following path extensions: png jpg jpeg gif tif tiff.

This definition matches for example the string https://www.gifs.com, which is clearly not an image URL.

I guess changing “includes” to “ends with” would be too restrictive: some valid image URLs might include query strings. How does iA Writer internally detect online image URLs?

Base directory of local file path isn’t defined

I'm using iA Writer together with Pandoc and have written a simple script to take care of file transclusion. While doing so, I found that there are some things you may want to clarify in the specs:

You use only relative paths in your examples, but to which directory are these paths relative? Suppose, I have three files: root.markdown, dir/foo.markdown, and dir/subdir/bar.markdown, and I want to transclude dir/subdir/bar.markdown in dir/foo.markdown and dir/foo.markdown in root.markdown. What would I say in dir/foo.markdown? That is, would I have to say /dir/subdir/bar.markdown or /subdir/bar.markdown?

Also, may I give absolute paths? Like, presumably, so: //absolute/path.markdown?

Don’t get me wrong, I can figure that out by trial and error, but, I find, this should be covered by the spec.

Command to automate file transclusion

This command automates the creation of a file with a list of all file names in the current folder preceded with /, to be used with iA Writer.

ls -m1 * | sed 's/^/\//'>> file-list.md

It would be nice to create a macOS service or workflow, asking the user to input the name of the file to be created inside the same directory.

Including plain text files as code blocks

Often I run a program e.g. python x.py > res.txt and want to include the output res.txt as a code block in iA using content blocks. Obviously, using the .txt extension will include it as normal text. As a workaround I sometimes use another extension e.g. res.r, but it would be nice if either there was a general extension like .out or .code, or if I could state explicitly when including the file that it should be a code block.

Add test suite

I’m trying to write a small implementation of Markdown-Content-Blocks in Go, with the goal of processing docs written in iA Writer. It would be nice to have a public test suite to be sure my implementation matches iA Writer’s implementation.

Disallow spaces in URLs

You currently have this example among others:

/Savings Account.csv 'Recent Transactions'

To enable future extensions, literal spaces should be disallowed in file paths, i.e. URLs.

/Savings%20Account.csv 'Recent Transactions'

I think it would be a bad idea to support any alternative escape syntax as found in shells and programming languages, e.g.:

/Savings\ Account.csv 'Recent Transactions'
/Savings\_Account.csv 'Recent Transactions'
/Savings_Account.csv 'Recent Transactions'
/Savings&#32;Account.csv 'Recent Transactions'
/Savings&#x20;Account.csv 'Recent Transactions'
(/Savings Account.csv) 'Recent Transactions'
"/Savings Account.csv" 'Recent Transactions'

Add metadata support

IA's content blocks are really useful to my workflow and I use them a lot. They would be much more useful if the metadata of trancluded blocks was hidden the same way it is in their own preview. Could this be done? Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.