Skip to content

Instantly share code, notes, and snippets.

@youxkei
Created December 1, 2018 04:24
Show Gist options
  • Save youxkei/ae4b87246c82774d8532f9b265c07db5 to your computer and use it in GitHub Desktop.
Save youxkei/ae4b87246c82774d8532f9b265c07db5 to your computer and use it in GitHub Desktop.
import std.stdio;
import std.array;
import std.algorithm;
import std.format;
import std.conv;
import std.range;
// gron scrapbox.json | rg 'lines\[' | rg --pcre2 -o '(?<= = ").*\S(?=";)' | sed -e 's/\\t/ /g' -e 's/&/\&amp;/g' -e 's/\\"/\&quot;/g' | ./scrapbox_to_opml
void main()
{
writeln(`<?xml version="1.0"?><opml version="2.0"><body>`);
int indent = -1;
stdin.byLineCopy.array.each!(delegate(line) {
int currentIndent = cast(int)line.until!(c => c != ' ').array.length;
foreach(_; 0..(indent - currentIndent + 1)) writeln("</outline>");
line = line[currentIndent..$];
auto splitted = line.split!(c => canFind("年月日", c));
if (splitted.length > 3) {
try {
int year = splitted[0].to!int;
int month = splitted[1].to!int;
int day = splitted[2].to!int;
line = format!"%4d-%02d-%02d"(year, month, day);
} catch (Exception _){}
}
writeln("<outline text=\"", line, "\">");
indent = currentIndent;
});
foreach(_; 0..(indent + 1)) writeln("</outline>");
writeln("</body></opml>");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment