diff --git a/editions/test/tiddlers/tests/test-filters.js b/editions/test/tiddlers/tests/test-filters.js index a79a242c8..628b41851 100644 --- a/editions/test/tiddlers/tests/test-filters.js +++ b/editions/test/tiddlers/tests/test-filters.js @@ -1062,7 +1062,7 @@ describe("Filter tests", function() { }); it("should handle the deserializers operator", function() { - var expectedDeserializers = ["application/javascript","application/json","application/x-tiddler","application/x-tiddler-html-div","application/x-tiddlers","text/css","text/html","text/plain","text/x-markdown"]; + var expectedDeserializers = ["application/javascript","application/json","application/x-tiddler","application/x-tiddler-html-div","application/x-tiddlers","text/css","text/html","text/markdown","text/plain","text/x-markdown"]; if($tw.browser) { expectedDeserializers.unshift("(DOM)"); } diff --git a/plugins/tiddlywiki/markdown/frontmatter-deserializer.js b/plugins/tiddlywiki/markdown/frontmatter-deserializer.js index 38bd31089..39dc3bbee 100644 --- a/plugins/tiddlywiki/markdown/frontmatter-deserializer.js +++ b/plugins/tiddlywiki/markdown/frontmatter-deserializer.js @@ -16,7 +16,7 @@ representation. var yaml = require("$:/plugins/tiddlywiki/markdown/yaml.js"); -exports["text/x-markdown"] = function(text,fields) { +function deserialize(text,fields) { var result = Object.create(null), body = text, frontmatter = null; @@ -76,7 +76,12 @@ exports["text/x-markdown"] = function(text,fields) { result.type = "text/x-markdown"; } return [result]; -}; +} + +// Register under both types — text/x-markdown is the deserializer type +// registered for .md file extensions; text/markdown is the raw content type. +exports["text/x-markdown"] = deserialize; +exports["text/markdown"] = deserialize; /* Convert a parsed YAML value to a tiddler field string. diff --git a/plugins/tiddlywiki/markdown/frontmatter-serializer.js b/plugins/tiddlywiki/markdown/frontmatter-serializer.js index 9750b1aeb..535b2afb6 100644 --- a/plugins/tiddlywiki/markdown/frontmatter-serializer.js +++ b/plugins/tiddlywiki/markdown/frontmatter-serializer.js @@ -32,7 +32,7 @@ var SKIP_FIELDS = { revision: true }; -exports["text/x-markdown"] = function(tiddler) { +function serialize(tiddler) { if(!tiddler) { return ""; } @@ -72,4 +72,10 @@ exports["text/x-markdown"] = function(tiddler) { return body; } return "---\n" + yaml.dump(frontmatter) + "\n---\n\n" + body; -}; +} + +// Register under both types — text/markdown is what the "New Markdown" button +// sets; text/x-markdown is what the deserializer uses after content-type +// resolution for .md files loaded from disk. +exports["text/x-markdown"] = serialize; +exports["text/markdown"] = serialize;