Current section
Files
Jump to
Current section
Files
README.md
# Arcdown[](https://circleci.com/gh/functionhaus/arcdown)Arcdown is a parsing library for articles written in Arcdown (.ad) format.It is written in pure Elixir/Erlang with no additional dependencies when beingused in production.# What is Arcdown (.ad) format?Arcdown (.ad) format is a lightweight file format for writing full-featuredcontent and articles as plain text in order to easily parse them as richobjects.The objective of this format is to allow the author to write full articlesin plain text in order to easily parse them into rich objects in whateverlanguage you're using.Arcdown supports the following features:* title* url slug* author name and email* topics and sub-topics* tags* article summary* article contentHere is an example article written in *Arcdown (.ad)* format:```The Day the Earth Stood Still <the-day-the-earth-stood-still>by Julian Blaustein <julian@blaustein.com>Filed under: Films > Sci-Fi > ClassicCreated @ 10:24pm on 1/20/2019Published @ 10:20pm on 1/20/2019* Sci-Fi* Horror* Thrillers* AliensSummary:A sci-fi classic about a flying saucer landing in Washington, D.C.---The Day the Earth Stood Still (a.k.a. Farewell to the Master and Journey to theWorld) is a 1951 American black-and-white science fiction film from 20th CenturyFox, produced by Julian Blaustein and directed by Robert Wise.```Arcdown doesn't presume that you want to parse the Article content/body in anyparticular way in order to give you as much flexibility as possible in itsusage. It's simple enough, however, to simply write the Article content asMarkdown (.md) and parse that later with a library like[Earmark](https://github.com/pragdave/earmark).It's suggested that Arcdown files with the content body written in Markdown usethe *.md.ad* file extension to remain conventionally consistent.Additional content parsing options may be included in the future, but for nowthe goal is to remain as content-agnostic as possible in order to give users thechoice of how format and write their own articles.## InstallationThe package can be installed by adding `arcdown` to your list ofdependencies in `mix.exs`:```elixirdef deps do [ {:arcdown, "~> 0.1"} ]end```Arcdown has no dependencies other than ex_doc which is only included in the `docs`context.## UsageParsing Arcdown text is easy thanks to a couple of helpers in the top-levelArcdown module. The default interface permits parsing Arcdown text eitherdirectly from a file, like this:```elixir{:ok, parsed} = Arcdown.parse_file "earth_stood_still.ad"```Or just by parsing the entire text from a string, like this:```elixirarticle_text = """The Day the Earth Stood Still <the-day-the-earth-stood-still>by Julian Blaustein <julian@blaustein.com>Filed under: Films > Sci-Fi > ClassicCreated @ 10:24pm on 1/20/2019Published @ 4:30am on 4/2/2019* Sci-Fi* Horror* Thrillers* AliensSummary:A sci-fi classic about a flying saucer landing in Washington, D.C.---The Day the Earth Stood Still (a.k.a. Farewell to the Master and Journey to theWorld) is a 1951 American black-and-white science fiction film from 20th CenturyFox, produced by Julian Blaustein and directed by Robert Wise."""{:ok, parsed} = Arcdown.parse article_text```In both instances, the parser will return a tuple in the format of`{:ok, %Arcdown.Article{}}`. The Article struct will contain all of its dataattributes fully parsed and formatted. Presuming that the text in both examplesabove match the string-parsing example, the resulting struct would look likethis:```elixir%Arcdown.Article{ author: "Julian Blaustein", content: "The Day the Earth Stood Still (a.k.a. Farewell to the Master and Journey to the\nWorld) is a 1951 American black-and-white science fiction film from 20th Century\nFox, produced by Julian Blaustein and directed by Robert Wise.\n", created_at: #DateTime<2019-01-20 22:24:00Z>, email: "julian@blaustein.com", published_at: #DateTime<2019-04-02 04:30:00Z>, slug: "the-day-the-earth-stood-still", summary: "A sci-fi classic about a flying saucer landing in Washington, D.C.", tags: [:sci_fi, :horror, :thrillers, :aliens], title: "The Day the Earth Stood Still", topics: ["Films", "Sci-Fi", "Classic"]}```### Arcdown FormattingBecause arcdown (.ad) files are parsed entirely with robust regular expressions,formatting must match the above example exactly.However not all of the above elements have to be included in an arcdown file.In fact it's perfectly acceptable to parse an empty file. Arcdown will justreturn an empty `%Arcdown.Article{}` struct.There are some situations in which extraneous whitespace `\s` and newline `\n`characters will be trimmed and ignored, but for the mostpart Arcdown wants youto follow its format as close to the letter as possible in order to not have tobloat its parsing logic with attempts to discern formatting errors.### The Arcdown HeaderYou're welcome to just parse header information, for example, if you haven'twritten your article yet but know how you want to title and categorize it.Here is an example of a complete header:```The Day the Earth Stood Still <the-day-the-earth-stood-still>by Julian Blaustein <julian@blaustein.com>Filed under: Films > Sci-Fi > ClassicCreated @ 10:24pm on 1/20/2019Published @ 10:20pm on 1/20/2019* Sci-Fi* Horror* Thrillers* AliensSummary:A sci-fi classic about a flying saucer landing in Washington, D.C.```Notice how there is no three-hyphen *content divider* ending the header texthere. The divider has semantic importance in parsing Arcdown files, and alwaysdenotes the beginning of a content section.If your article contains no content yet, exclude the trailing divider.### Arcdown ContentThe *Content* portion of an Arcdown file always begins with the hyphen divider`---` followed by two newline characters.This is a valid Arcdown file in which the parser will simply extract the contentbody and ignore any header parsing in the absence of header data:```---The Day the Earth Stood Still (a.k.a. Farewell to the Master and Journey to theWorld) is a 1951 American black-and-white science fiction film from 20th CenturyFox, produced by Julian Blaustein and directed by Robert Wise.```Omitting the hyphen divider `---` element will suggest to the parser that thisis actually the title of the article rather than the content. As such, thedivider must begin the parsed string, followed by two newlines, like this:`---\n\nContent goes here.`## AvailabilityThis library is currently published at for use with the public hex.pmrepository at https://hex.pm/packages/arcdown.Source code is available at the [FunctionHaus Github Organization](https://github.com/functionhaus) athttps://github.com/functionhaus/arcdown.## LicenseArcdown source code is released under Apache 2 License.Check LICENSE file for more information.