npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@atjson/source-mobiledoc

v0.23.41

Published

Create atjson documents from Mobiledoc

Downloads

177

Readme

💼 @atjson/source-mobiledoc

Mobiledoc is a format created by 201 Created for use on Bustle, a publisher focusing on Millenial Women.

The primary mechanism in which Mobiledoc provides extensibility is using two types of primitives, atoms and cards. Comparably, atoms are akin to inline annotations and cards map fairly cleanly to object annotations.

Mobiledoc's format is represented using HTML tags for built-in elements, which contain sections and markup.

🗺 How does Mobiledoc map into annotations?

All markup and sections provided by Mobiledoc have corresponding annotations. These annotations are:

| Name | Annotation type | | -------------- | ----------------------- | | Links | -mobiledoc-a | | Pull Quote | -mobiledoc-aside | | | -mobiledoc-pull-quote | | Headings | -mobiledoc-h1 | | | -mobiledoc-h2 | | | -mobiledoc-h3 | | | -mobiledoc-h4 | | | -mobiledoc-h5 | | | -mobiledoc-h6 | | Image | -mobiledoc-img | | Italic | -mobiledoc-em | | List Item | -mobiledoc-li | | Numbered List | -mobiledoc-ol | | Bulleted List | -mobiledoc-ol | | Paragraph | -mobiledoc-p | | Strike-through | -mobiledoc-s | | Bold | -mobiledoc-strong | | Subscript | -mobiledoc-sub | | Superscript | -mobiledoc-sup | | Underline | -mobiledoc-u |

💁‍♀️ If you are a developer using Mobiledoc and have made custom extensions to Mobiledoc to support more sections or other types of markup, the bits of code that you'll need are the following:

  1. An annotation definition for your Mobiledoc extension
  2. A custom extension of the Mobiledoc source

Let's do this for a custom extension that adds code to Mobiledoc's markups.

import { InlineAnnotation } from '@atjson/document';

export default Code extends InlineAnnotation {
  static vendorPrefix = 'mobiledoc';
  static type = 'code';
}
import MobiledocSource from '@atjson/source-mobiledoc';
import Code from './annotations/code';

export default MyMobiledocSource extends MobiledocSource {
  static schema = [...MobiledocSource.schema, Code];
}

Now, when a document with a code markup is converted from Mobiledoc into AtJSON, you'll see code annotations, instead of unknown annotations.

🎴 Cards

Cards are Mobiledoc's primary tool for adding custom bits to documents. To turn a card into an annotation, you'll need to follow the same steps as adding a custom extension, except instead of naming it code, you'll name it the name of your card followed by -card. Because Mobiledoc has separate buckets for their extensions, we're adding -card to the end to make it easier to analyze your content as well as to make it clearer what's going on.

If there's a photo card in Mobiledoc, with id, size, and caption properties on it, we can map this into an annotation by writing the following code:

import { ObjectAnnotation } from '@atjson/document';

export default PhotoCard extends ObjectAnnotation<{
  id: string;
  size: 'small' | 'medium' | 'large';
  caption?: string;
}> {
  static vendorPrefix = 'mobiledoc';
  static type = 'photo-card';
}
import MobiledocSource from '@atjson/source-mobiledoc';
import PhotoCard from './annotations/photo-card';

export default MyMobiledocSource extends MobiledocSource {
  static schema = [...MobiledocSource.schema, PhotoCard];
}

⚛️ Atoms

Atoms work the same as cards, but instead of ending with -card, you'll end the name of your annotation with -atom.

Let's go through the exercise of adding a mention atom that works like Twitter handles or @ mentions in Slack.

import { InlineAnnotation } from '@atjson/document';

export default MentionAtom extends InlineAnnotation<{
  id: string;
}> {
  static vendorPrefix = 'mobiledoc';
  static type = 'mention-atom';
}
import MobiledocSource from '@atjson/source-mobiledoc';
import MentionAtom from './annotations/mention-atom';

export default MyMobiledocSource extends MobiledocSource {
  static schema = [...MobiledocSource.schema, MentionAtom];
}

🤷‍♀️ What is a Mobiledoc?

Mobiledoc is a JSON representation of a document with a few notable bits. The format is a compressed tree view of a document, where metadata about the document is mostly stored apart from the contents.

Mobiledoc's storage format is most similar to AtJSON's heirarchical intermediate representation (hir), which shows a derived form of AtJSON's text + annotations model.

Read up more on the format itself.

📚 Read More

  • http://bustle.github.io/mobiledoc-kit/demo/docs/