Coder Social home page Coder Social logo

smarkt's Introduction

๐Ÿ“ƒ smarkt

Hyper-readable structure for defining fields and values in plain text

Usage

Transform some structured plain text including Markdown and YAML into JSON, and visa versa. Super useful for archivability and readability. Feature parity with Kirbyโ€™s file structure.

var smarkt = require('smarkt')

var str = smarkt.parse(`
title: Cyber Mysticism
----
tags:
  - technopastoral
  - ambient
----
text: Art has always been a focusing device, the frame is a focusing device. What Iโ€™m trying to do is eliminate the frame, eliminate all those distractions and put you in direct relationship to the real experience and the real power: your ability to perceive.
`)

var obj = smarkt.stringify({
  title: 'Cyber Mysticism',
  { tags: ['technopastoral', 'ambient']},
  text: 'Art has always been a focusing device, the frame is a focusing device. What Iโ€™m trying to do is eliminate the frame, eliminate all those distractions and put you in direct relationship to the real experience and the real power: your ability to perceive.'
})

Structure

A plain-text file is separated into fields delineated by four dashes.

----

Give the field a name and define itโ€™s value.

title: Cyber Mysticism

The value can also be YAML.

tags:
  - technopastoral
  - ambient
Plain text input expanded
title: Cyber Mysticism
----
tags:
  - technopastoral
  - dark-ux
----
design:
  desktop:
    background: red
    navigation: false
  mobile:
    background: blue
    navigation: true
----
text:

Information wants to be free.
JSON output expanded
{
  "title": "Cyber Mysticism",
  "tags": ["technopastoral", "dark-ux"],
  "design": {
    "desktop": {
      "background": "red",
      "navigation": false
    },
    "mobile": {
      "background": "blue",
      "navigation": true
    }
  },
  "text": "Information wants to be free."
}

Methods

stringify

Accepts a single argument which must be type string. Returns an object.

parse

Accepts a single argument which must be type object. Returns a string.

Alternate usage

var stringify = require('smarkt/stringify')
var parse = require('smarkt/parse')

Sometimes itโ€™s handy just to access a single method to reduce bundle size. To do this, simply require the desired method by name.

Todo

  • Tests
  • .stringify Remove quotes around YAML array values

smarkt's People

Contributors

jondashkyle avatar lachenmayer 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

Watchers

 avatar  avatar  avatar

smarkt's Issues

Digesting YAML objects

Right now setting YAML object as a field value fails.

cities: 
  losangeles:
    name: Los Angeles
    country: USA
  tokyo:
    name: Tokyo
    country: Japan

Todo

  • stringify
  • parse

Markdown compatiblity

I think this breaks currently:

title: A test document
----
tags:
  - tomato
  - paprika
----
text:

# This is markdown

With paragraphs, and now..

Head
----

Markdown actually allows this in most specifications.```

Paged content

It would be great if multi-part (paged) content could be specified via an array syntax.

My proposal looks like:

content[]:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris tincidunt convallis leo, vitae hendrerit ipsum euismod et. 

Sed sem augue, ornare eu interdum id, semper sit amet leo. Nullam a accumsan velit. Mauris sed lacus eleifend, rhoncus dui ultricies, mollis libero.

----
content[]:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris tincidunt convallis leo, vitae hendrerit ipsum euismod et. 

Sed sem augue, ornare eu interdum id, semper sit amet leo. Nullam a accumsan velit. Mauris sed lacus eleifend, rhoncus dui ultricies, mollis libero.

In the parsing stage, keys that match

/\[\]$/

can be added to JSON with Array.push().

In the serialization stage, if the object is an array but matches the above pattern, it's serialized as a series of plain text fields.

I'm not sure if this is more appropriate at the smarkt level, or should be delegated to when you process the JSON (e.g. through a delimiter inside the plain text field)

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.