DocumentApp.getUi().createMenu('Markdown Converter')
.addItem('Markdown to DokuWiki', 'convertMarkdownToDokuWiki')
.addItem('Markdown to Google Docs', 'convertMarkdownToGoogleDocs')
.addItem('Google Docs to DokuWiki', 'convertGoogleDocsToDokuWiki')
function convertGoogleDocsToDokuWiki() {
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
for (var i = 0; i < body.getNumChildren(); i++) {
var element = body.getChild(i);
output.push(parseElementToDokuWiki(element));
var dokuwikiText = output.filter(line => line !== "").join("\n\n");
showConvertedText(dokuwikiText);
function formatInlineStyles(text, element) {
var textElement = element.editAsText();
for (var i = 0; i < text.length; i++) {
if (textElement.isBold(i)) {
newText = applyFormatting(newText, boldWords, "**");
for (var i = 0; i < text.length; i++) {
if (textElement.isItalic(i)) {
newText = applyFormatting(newText, italicWords, "//");
var linkMatches = [...text.matchAll(/\[(.+?)\]\((https?:\/\/[^\s)]+)\)/g)];
linkMatches.forEach(match => {
newText = newText.replace(match[0], "[" + linkText + "](/" + url + "/)");
function applyFormatting(text, indexes, markup) {
if (indexes.length === 0) return text;
for (var i = 0; i < text.length; i++) {
if (indexes.includes(i) && !inWord) {
formattedText += text[i];
if (!indexes.includes(i + 1) && inWord) {