Search

I would like to apply markdown to a static XML datasource. Is this possible?

In general, how exactly does markdown work in symphony? It transforms entries at the time of posting them to the database, and xhtml is stored in DB? So therefore we cannot get our markdown notated text back in the frontend (and need the html to markdown utility)? But then how does it appear back in the backend?

AFAIK, both versions are saved in the database: the "pure" (Markdown) text and the XHTML produced by the Markdown extension.

It's certainly strange to use an HTML to Markdown utility to edit your entries on the frontend. Isn't it possible to edit the original entry (Markdown) directly, then "resave" everything (thus performing a new Markdown conversion, as you do in the backend)?

(I admit, I myself created such a utility. But it serves a different purpose.)

Michael, I feel the same, its strange to convert html back to md for frontend editing, yet I do it, and I think that bauhause does it too. I suppose because a special event, or even system hack, would be needed to provide a DS with the original text from the DB?

As for applying md on a static XML file specified as a datasource, I would like to edit the file with my texteditor via ftp and save it. But still use md. Markdown hooks in between the form and the save, so there is no way to have it work on a xml file in the workspace?

or...is there a way to have an uploaded file added as an entry?

I use the HTML-to-Markdown XSL templates for the very reason michael-e refers to: I have a textarea with a Markdown formatter so I can retain line breaks and basic styling. However users of the site need to edit this text through a front-end form (it is the Description field of a user profile). A Data Source only supplies the HTML version, so I use XSL to convert back to Markdown for use in the HTML textarea.

The other day I noticed that a field can add multiple output options to the Included Fields list in the Data Source editor. I wonder whether a textarea with a formatter applied could provide two options. My Description textarea could perhaps offer me:

  • Description (Markdown)
  • Description (HTML)

When building a DS one chooses which they want to output.

As for a Static XML transformation, I'm still not 100% sure of what you're trying to achieve newnomad. You could write a custom PHP script to open the Static XML data source file, output the editable node into a textarea (converting it to Markdown), and when the form is saved your PHP converts to HTML and re-injects this back to the Static XML file. But that sounds rather long-winded for something that can be achieved with Section/Fields and the HTML-to-Markdown XSL...

Nick, I have setup a system in which an entire site is based on markdown notated text in 1 entry. The 'client/author' can edit this text via frontend in a textarea. Now I want to use this system for my personal site. I would just like to be able to write this markdown notated text in my Espresso texteditor (with code folding and other cool features) and upload it as an xml file. Then later, by using espresso' sbuilt in ftp features, I can just edit the file in Espresso, without having to log into my front or backend. Pretty much like you would edit a page template or xml file with hardcoded content, only now I dont have to write in xhtml, but I can use markdown.

My suggestion would be to store your Markdown text in a plain text file. You can then write a small PHP script to read this contents, process Markdown-to-HTML, and include this as a Dynamic XML data source.

Something like this perhaps:

<?php
include_once('markdown.php');
$text = file_get_contents('markdown_content.txt');
echo(Markdown($text));

Then create a Dynamic XML data source pointing to this page.

great thanks Nick!

1

I think Allen once replied he would just edit a xhtml then.

What workflow do you use for edting static files?

  • xhtml in a convenient codesensing editor
  • markdown in this editor, and then transform to xhtml in the editor (as espresso can)
  • other

I wonder if it would be usefull to have a markdown WMD (like this textarea) style sugar for espresso…

2

The other day I noticed that a field can add multiple output options to the Included Fields list in the Data Source editor. I wonder whether a textarea with a formatter applied could provide two options

Can anyone confirm if we can have a DS include raw markdown instead of the xhtml, simply by a setting in the DS editor? Or would it need a new DS editor or a extension?

Is it currently still not possible to have a DS that presents markdown formatted text?

This would be an update to the Textarea field itself rather than a Data Source, I think. But at the moment, no it is not possible. If you need this functionality, you could look into Rowan’s Subsection field which outputs entries in two ways into the XML (provides two options in the Included Elements list in the DS options). You could then see how he does this and submit these changes to the Textarea field.

Resurrecting a fairly old thread, here, but thanks Nick for the example of how to parse a markdown text file. I was able to get a single markdown file I made, parsed into HTML.

However, when I point a Dynamic XML datasource at my url, it does not include the output in the ?debug view, even confirming it is attached.

Is it possible attach a generic HTML output like this? Or do I need to convert the page further, into something like Atom? Or somehow embed the above PHP snippet into an XHTML page, or something similar?

Appreciate anyone’s comment on this matter. Thanks!

Is it possible attach a generic HTML output like this

Markdown should create valid XHTML, which in turn is valid XML. So you should be able to include Markdown output in your Dynamic XML data source.

I suspect the problem is twofold:

Firstly your script creating the Markdown is sending the response as plain text, rather than XML. Try:

header('Content-Type: text/xml');

If you view this a browser like Firefox it will try and render the result as an XML document tree, rather than plain text. The benefit of this is that it will tell you any XML parsing errors, directly in your browser.

Secondly, I imagine the output is not valid XML. If your Markdown output looks like:

<p>Hello</p>
<p>World</p>

Then this is invalid because there is no root node (an XML document must have one, and one only, root node in which all other nodes sit). When you output the response, try:

echo('<content>' . Markdown($text) . '</content>');

Which should render valid XML.

<content>
    <p>Hello</p>
    <p>World</p>
</content>

A third possibility is that the output may require an XML declaration for Symphony to correctly parse the document. So you may need the first line of your script output to be:

<?xml version="1.0" encoding="utf-8" ?>

Thank you very much Nick - that gives me a clear idea of what is wrong. I will test and post back.

Regards,
Rick

Nick - closing the loop, that was indeed it. I can see the xml from my markdown page now. :-) Thanks!

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details