mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-05-15 01:42:18 +00:00
Register for text/x-markdown as well as text/markdown
This commit is contained in:
@@ -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)");
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user