Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

markdown/pagemodel: Added support for Github code block #50

Merged
merged 1 commit into from
Dec 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions plugin/src/winterwell/markdown/pagemodel/MarkdownPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ private void setText(String text) {
Header currentHeader = dummyTopHeader;
// Identify line types
int lineNum = 0;
IPreferenceStore pStore = Activator.getDefault().getPreferenceStore();

// Multi-markdown header
if (multiMarkdownSupport) {
// The key is the text before the colon, and the data is the text
Expand Down Expand Up @@ -328,6 +330,32 @@ private void setText(String text) {
if (dummyTopHeader.getSubHeaders().size() == 0) {
level1Headers.remove(dummyTopHeader);
}

boolean githubSyntaxSupport =
pStore.getBoolean(MarkdownPreferencePage.PREF_GITHUB_SYNTAX);
if (githubSyntaxSupport) {
/*
* Support Code block
*/
boolean inCodeBlock = false;
for (lineNum = 0; lineNum < lines.size(); lineNum++) {
String line = lines.get(lineNum);
// Found the start or end of a code block
if (line.matches("^```.*\n")) {
// We reverse the boolean value
inCodeBlock = !inCodeBlock;

// We force the line to be blank. But we mark it as normal
// to prevent to be stripped
lines.set(lineNum, "\n");
lineTypes.set(lineNum, KLineType.NORMAL);
continue;
}
if (inCodeBlock) {
lines.set(lineNum, " " + line);
}
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class MarkdownPreferencePage
public static final String PREF_CODE = "Pref_Code";
public static final String PREF_CODE_BG = "Pref_Code_Background";

public static final String PREF_GITHUB_SYNTAX = "Pref_Github_Syntax";

private static final RGB DEF_DEFAULT = new RGB(0, 0, 0);
private static final RGB DEF_COMMENT = new RGB(128, 0, 0);
private static final RGB DEF_HEADER = new RGB(0, 128, 0);
Expand All @@ -71,6 +73,7 @@ public static void setDefaultPreferences(IPreferenceStore pStore) {
pStore.setDefault(PREF_TASK_TAGS_DEFINED, "TODO,FIXME,??");
pStore.setDefault(PREF_MARKDOWN_COMMAND, MARKDOWNJ);
pStore.setDefault(PREF_SECTION_NUMBERS, true);
pStore.setDefault(PREF_GITHUB_SYNTAX, true);

PreferenceConverter.setDefault(pStore, PREF_DEFUALT, DEF_DEFAULT);
PreferenceConverter.setDefault(pStore, PREF_COMMENT, DEF_COMMENT);
Expand Down Expand Up @@ -141,6 +144,16 @@ public void createFieldEditors() {

ColorFieldEditor codeBg = new ColorFieldEditor(PREF_CODE_BG, "Code Background", getFieldEditorParent());
addField(codeBg);

/*
* Fields for the preview window
*/

// Github Syntax support
fd = new BooleanFieldEditor(PREF_GITHUB_SYNTAX,
"Support Github Syntax",
getFieldEditorParent());
addField(fd);
}

/* (non-Javadoc)
Expand Down