Skip to content
This repository has been archived by the owner on Jan 10, 2022. It is now read-only.

using markdown in content #237

Open
laurelnaiad opened this issue Sep 29, 2013 · 2 comments
Open

using markdown in content #237

laurelnaiad opened this issue Sep 29, 2013 · 2 comments

Comments

@laurelnaiad
Copy link
Contributor

I'm planning to enable the use of markdown for content instead of html.

There are several ways I could (or might be able to) do this.

My goal is to find or create a place in the framework to do this kind of content processing, and to enable the use of modules to do it -- markdown processing would be one option, but of course others could be authored as modules as well.

I'd like to allow content processing at content creation time such that one can author the content (and have it be saved as the content definition) and also have the final result (html) pre-generated for use when displaying. I guess this would alter the content schema :(

If that won't fly, I can personally live with doing the source->html transformation at runtime, in which case I guess I'm looking at Theme.js

Any thoughts?

I'm not going to launch into this today, FYI. I still have some learning to do -- and more importantly wanted to get a discussion going about how to do content processing of this sort.

@richtera
Copy link
Collaborator

Have you looked into this any more? I like the idea. I am planning to make some time on the weekend to get things cleaned up. I have had a lot of things going on.

@laurelnaiad
Copy link
Contributor Author

I did look at it. It seemed the path of least resistance, though not the best architecture, was to do this in the theme. This is some coffeescript that I wrote to live in the theme. It uses async b/c I prefer it, pygmentize-bundled, which requires python (I wanted code formatting and pygmentize is the best), and marked.

marked = require 'marked'
pygmentize = require 'pygmentize-bundled'
async = require 'async'

opts = {
  gfm: true
  tables: true
  breaks: false
  pedantic: false
  sanitize: true
  highlight: (code, lang, callback) ->
    console.log 'pygmentizing'

    switch lang
      when 'js' then myLang = 'js'
      else myLang = lang

    pygmentize(
      {
        lang: myLang
        format: 'html'
        options:
          cssclass: 'codehilite'
          # nowrap: true
          linenos: true
      }
      code
      (err, result) ->
        if err
          callback err
        else
          callback null, result.toString()
    )
}

module.exports = {
  markdown: (contentObj, callback) ->
    async.waterfall(
      [
        doMarked = (cb) ->
          marked contentObj.content, opts, cb
      ]
      done = (err, rendered) ->
        contentObj.content = rendered
        callback err, contentObj
    )
}

The package.json for the theme:

{
  "name": "my-calipso-theme",
  "description": "my calipso theme",
  "version": "0.0.1",
  "dependencies": {
    "pygmentize-bundled": "~2.1.0",
    "marked": "~0.2.9",
    "async": "~0.2.9"
  }
}

In use:

calipso = require 'calipso'
async = require 'async'
renderer = require '../../renderer'

module.exports = (req, options, callback) ->

  async.waterfall(
    [
      getContent = (cb) ->
        options.getContent req, { alias: "lorem", clickEdit: false }, cb
      render = (contentObj, cb) ->
        renderer.markdown contentObj, cb
    ]
    done = (err, contentObj) ->
      if req.session && req.session.user && req.session.user.isAdmin
        contentObj.content = "
          <div title=\"#{req.t("Double click to edit content block ...")}\"
          class=\"content-block\" id=\"#{contentObj._id}\">
          #{contentObj.content}</div>"
      callback err, { content: contentObj.content }
  )

I also added compass support. In app.js:

   if (app.config.get('libraries:compass:enable')) {
      app.mwHelpers.compassMiddleware = function (themePath) {
        var getConfig = function(name) {
          return app.config.get('libraries:compass:' + name);
        };

        var mw = compass({
          project: themePath,
          sass: getConfig('sourceDir'),
          css: getConfig('destDir'),
          libs: getConfig('libs'),
          img: getConfig('imgDir'),
          cache: getConfig('cache'),
          logging: getConfig('logging'),
          mode: getConfig('mode')
        });
        mw.tag = 'theme.compass';
        return mw;
      };
      app.use(app.mwHelpers.compassMiddleware(''));
    }

And, to make a long story short, the more I dug into the architecture, the more
time I felt myself spending on working around it than with it. I hate to say
it, but my ultimate conclusion was that Calipso and I were not a good fit.

I wanted something that was more content management, I wanted something that
made fewer assumptions about the use HTML and jQuery. So I have stopped
working on this project.

In any case, I just dumped that code in this issue so that you might leverage
it if you revisit markdown. I have a feeling it won't be of use, but there it
is, anyway.

Thank your for working with me as I explored.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants