Skip to content
This repository has been archived by the owner on Dec 20, 2017. It is now read-only.

Commit

Permalink
#34 : Upgrade to Pegdown 1.4.2 (adds support for Github strikethrough…
Browse files Browse the repository at this point in the history
… text)
  • Loading branch information
nicoulaj committed May 10, 2014
1 parent 67e64af commit 98d1543
Show file tree
Hide file tree
Showing 18 changed files with 112 additions and 5 deletions.
Binary file not shown.
Binary file not shown.
Binary file removed lib/pegdown-1.4.1.jar
Binary file not shown.
Binary file added lib/pegdown-1.4.2.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,17 @@ public void visit(SpecialTextNode node) {
addToken(node, SPECIAL_TEXT);
}

/**
* Visit the {@link StrikeNode}.
*
* @param node the {@link StrikeNode} to visit
*/
@Override
public void visit(StrikeNode node) {
addToken(node, STRIKETHROUGH);
visitChildren(node);
}

/**
* Visit the {@link StrongEmphSuperNode}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@ public MarkdownColorSettingsPage() {
MarkdownHighlighterColors.BOLD_ATTR_KEY)
);
attributeDescriptors.add(new AttributesDescriptor(
MarkdownBundle.message("markdown.editor.colorsettingspage.italic"),
MarkdownHighlighterColors.ITALIC_ATTR_KEY)
MarkdownBundle.message("markdown.editor.colorsettingspage.italic"),
MarkdownHighlighterColors.ITALIC_ATTR_KEY)
);
attributeDescriptors.add(new AttributesDescriptor(
MarkdownBundle.message("markdown.editor.colorsettingspage.strikethrough"),
MarkdownHighlighterColors.STRIKETHROUGH_ATTR_KEY)
);
attributeDescriptors.add(new AttributesDescriptor(
MarkdownBundle.message("markdown.editor.colorsettingspage.explicit-link"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ public class MarkdownHighlighterColors {
/** Default style for italic text. */
public static final TextAttributesKey ITALIC_ATTR_KEY = createTextAttributesKey("MARKDOWN.ITALIC", STRING);

/** Default style for strikethrough text. */
public static final TextAttributesKey STRIKETHROUGH_ATTR_KEY = createTextAttributesKey("MARKDOWN.STRIKETHROUGH", STRING);

/** Default style for images. */
public static final TextAttributesKey IMAGE_ATTR_KEY = createTextAttributesKey("MARKDOWN.IMAGE", STRING);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class MarkdownSyntaxHighlighter extends SyntaxHighlighterBase {
fillMap(ATTRIBUTES, MarkdownTokenTypeSets.TABLE_SET, MarkdownHighlighterColors.TABLE_ATTR_KEY);
fillMap(ATTRIBUTES, MarkdownTokenTypeSets.HRULE_SET, MarkdownHighlighterColors.HRULE_ATTR_KEY);
fillMap(ATTRIBUTES, MarkdownTokenTypeSets.SPECIAL_TEXT_SET, MarkdownHighlighterColors.SPECIAL_TEXT_ATTR_KEY);
fillMap(ATTRIBUTES, MarkdownTokenTypeSets.STRIKETHROUGH_SET, MarkdownHighlighterColors.STRIKETHROUGH_ATTR_KEY);
fillMap(ATTRIBUTES, MarkdownTokenTypeSets.EXPLICIT_LINK_SET, MarkdownHighlighterColors.EXPLICIT_LINK_ATTR_KEY);
fillMap(ATTRIBUTES, MarkdownTokenTypeSets.IMAGE_SET, MarkdownHighlighterColors.IMAGE_ATTR_KEY);
fillMap(ATTRIBUTES, MarkdownTokenTypeSets.REFERENCE_IMAGE_SET, MarkdownHighlighterColors.REFERENCE_IMAGE_ATTR_KEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public interface MarkdownTokenTypeSets extends MarkdownTokenTypes {
/** Special text token type set. */
TokenSet SPECIAL_TEXT_SET = TokenSet.create(SPECIAL_TEXT);

/** Strikethrough token type set. */
TokenSet STRIKETHROUGH_SET = TokenSet.create(STRIKETHROUGH);

/** Link token type set. */
TokenSet EXPLICIT_LINK_SET = TokenSet.create(EXPLICIT_LINK);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public interface MarkdownTokenTypes extends TokenType {
/** Special text token type. */
IElementType SPECIAL_TEXT = new MarkdownElementType("SPECIAL_TEXT");

/** Strikethrough token type. */
IElementType STRIKETHROUGH = new MarkdownElementType("STRIKETHROUGH");

/** Link token type. */
IElementType EXPLICIT_LINK = new MarkdownElementType("EXPLICIT_LINK");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public class MarkdownGlobalSettings implements PersistentStateComponent<Element>
/** Whether the "Suppress inline HTML tags" extension should be enabled. */
private boolean suppressInlineHTML = false;

/** Whether the "Strikethroughs" extension should be enabled. */
private boolean strikethrough = false;

/**
* Get the instance of this service.
*
Expand Down Expand Up @@ -113,6 +116,27 @@ public void setParsingTimeout(int parsingTimeout) {
}
}

/**
* Whether the "Strikethroughs" extension should be enabled.
*
* @return {@link #strikethrough}
*/
public boolean isStrikethrough() {
return strikethrough;
}

/**
* Whether the "Strikethroughs" extension should be enabled.
*
* @param strikethrough whether the "Suppress inline HTML tags" extension should be enabled.
*/
public void setStrikethrough(boolean strikethrough) {
if (this.strikethrough != strikethrough) {
this.strikethrough = strikethrough;
notifyListeners();
}
}

/**
* Whether the "Suppress inline HTML tags" extension should be enabled.
*
Expand Down Expand Up @@ -364,6 +388,7 @@ public Element getState() {
element.setAttribute("fencedCodeBlocks", Boolean.toString(fencedCodeBlocks));
element.setAttribute("suppressHTMLBlocks", Boolean.toString(suppressHTMLBlocks));
element.setAttribute("suppressInlineHTML", Boolean.toString(suppressInlineHTML));
element.setAttribute("strikethrough", Boolean.toString(strikethrough));
return element;
}

Expand Down Expand Up @@ -398,6 +423,8 @@ public void loadState(@NotNull Element element) {
if (value != null) suppressHTMLBlocks = Boolean.parseBoolean(value);
value = element.getAttributeValue("suppressInlineHTML");
if (value != null) suppressInlineHTML = Boolean.parseBoolean(value);
value = element.getAttributeValue("strikethrough");
if (value != null) strikethrough = Boolean.parseBoolean(value);
notifyListeners();
}

Expand All @@ -418,7 +445,8 @@ public int getExtensionsValue() {
(definitions ? Extensions.DEFINITIONS : 0) +
(fencedCodeBlocks ? Extensions.FENCED_CODE_BLOCKS : 0) +
(suppressHTMLBlocks ? Extensions.SUPPRESS_HTML_BLOCKS : 0) +
(suppressInlineHTML ? Extensions.SUPPRESS_INLINE_HTML : 0);
(suppressInlineHTML ? Extensions.SUPPRESS_INLINE_HTML : 0) +
(strikethrough ? Extensions.STRIKETHROUGH : 0);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ public boolean isModified() {
|| settingsPanel.smartsCheckBox == null || globalSettings.isSmarts() != settingsPanel.smartsCheckBox.isSelected()
|| settingsPanel.suppressHTMLBlocksCheckBox == null || globalSettings.isSuppressHTMLBlocks() != settingsPanel.suppressHTMLBlocksCheckBox.isSelected()
|| settingsPanel.suppressInlineHTMLCheckBox == null || globalSettings.isSuppressInlineHTML() != settingsPanel.suppressInlineHTMLCheckBox.isSelected()
|| settingsPanel.tablesCheckBox == null || globalSettings.isTables() != settingsPanel.tablesCheckBox.isSelected();
|| settingsPanel.tablesCheckBox == null || globalSettings.isTables() != settingsPanel.tablesCheckBox.isSelected()
|| settingsPanel.strikethroughCheckBox == null || globalSettings.isStrikethrough() != settingsPanel.strikethroughCheckBox.isSelected();
}

/** Apply modifications to the settings done in the UI. */
Expand All @@ -144,6 +145,7 @@ public void apply() {
globalSettings.setSuppressHTMLBlocks(settingsPanel.suppressHTMLBlocksCheckBox != null && settingsPanel.suppressHTMLBlocksCheckBox.isSelected());
globalSettings.setSuppressInlineHTML(settingsPanel.suppressInlineHTMLCheckBox != null && settingsPanel.suppressInlineHTMLCheckBox.isSelected());
globalSettings.setTables(settingsPanel.tablesCheckBox != null && settingsPanel.tablesCheckBox.isSelected());
globalSettings.setStrikethrough(settingsPanel.strikethroughCheckBox != null && settingsPanel.strikethroughCheckBox.isSelected());
}
}

Expand All @@ -162,6 +164,7 @@ public void reset() {
if (settingsPanel.suppressHTMLBlocksCheckBox != null) settingsPanel.suppressHTMLBlocksCheckBox.setSelected(globalSettings.isSuppressHTMLBlocks());
if (settingsPanel.suppressInlineHTMLCheckBox != null) settingsPanel.suppressInlineHTMLCheckBox.setSelected(globalSettings.isSuppressInlineHTML());
if (settingsPanel.tablesCheckBox != null) settingsPanel.tablesCheckBox.setSelected(globalSettings.isTables());
if (settingsPanel.strikethroughCheckBox != null) settingsPanel.strikethroughCheckBox.setSelected(globalSettings.isStrikethrough());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</component>
</children>
</grid>
<grid id="5fdf9" binding="extensionsPanel" layout-manager="GridLayoutManager" row-count="11" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="5fdf9" binding="extensionsPanel" layout-manager="GridLayoutManager" row-count="12" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
Expand Down Expand Up @@ -270,6 +270,26 @@
<text resource-bundle="net/nicoulaj/idea/markdown/localization/strings" key="markdown.settings.wiki-links.description"/>
</properties>
</component>
<component id="a194b" class="javax.swing.JCheckBox" binding="strikethroughCheckBox">
<constraints>
<grid row="11" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="125" height="23"/>
</grid>
</constraints>
<properties>
<text resource-bundle="net/nicoulaj/idea/markdown/localization/strings" key="markdown.settings.strikethrough.label"/>
<toolTipText resource-bundle="net/nicoulaj/idea/markdown/localization/strings" key="markdown.settings.strikethrough.label"/>
</properties>
</component>
<component id="845c0" class="javax.swing.JLabel">
<constraints>
<grid row="11" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font style="2"/>
<text resource-bundle="net/nicoulaj/idea/markdown/localization/strings" key="markdown.settings.strikethrough.description"/>
</properties>
</component>
</children>
</grid>
</children>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public class MarkdownSettingsPanel {
/** Form element for {@link MarkdownGlobalSettings#suppressInlineHTML}. */
public JCheckBox suppressInlineHTMLCheckBox;

/** Form element for {@link MarkdownGlobalSettings#strikethrough}. */
public JCheckBox strikethroughCheckBox;

/** Description label for {@link #suppressInlineHTMLCheckBox}. */
private JLabel suppressInlineHTMLDescriptionLabel;

Expand Down Expand Up @@ -112,4 +115,7 @@ public class MarkdownSettingsPanel {

/** Description label for {@link #smartsCheckBox}. */
private JLabel smartsDescriptionLabel;

/** Description label for {@link #strikethroughCheckBox}. */
private JLabel strikethroughDescriptionLabel;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ markdown.editor.colorsettingspage.sample-loading-error=Failed loading sample doc
markdown.editor.colorsettingspage.text=Text
markdown.editor.colorsettingspage.bold=Bold text
markdown.editor.colorsettingspage.italic=Italic text
markdown.editor.colorsettingspage.strikethrough=Strikethrough text
markdown.editor.colorsettingspage.explicit-link=Explicit link
markdown.editor.colorsettingspage.image=Image
markdown.editor.colorsettingspage.reference-image=Reference image
Expand Down Expand Up @@ -82,6 +83,7 @@ markdown.settings.smarts.label=Smarts
markdown.settings.wiki-links.label=Wiki links
markdown.settings.suppress-inline-html.label=Suppress inline HTML
markdown.settings.suppress-html-blocks.label=Suppress HTML blocks
markdown.settings.strikethrough.label=Strikethrough
markdown.settings.quotes.description=SmartyPants style pretty single and double quotes.
markdown.settings.smarts.description=SmartyPants style pretty ellipsises, dashes and apostrophes.
markdown.settings.fenced-code-block.description=PHP Markdown Extra style fenced code blocks.
Expand All @@ -93,3 +95,4 @@ markdown.settings.hard-wraps.description=Github style hard wraps parsing as HTML
markdown.settings.wiki-links.description=Wiki-style links.
markdown.settings.suppress-inline-html.description=Suppress inline HTML tags. They will be accepted in the input but not be contained in the output.
markdown.settings.suppress-html-blocks.description=Suppress HTML blocks. They will be accepted in the input but not be contained in the output.
markdown.settings.strikethrough.description=Support strikethroughs as supported in Pandoc and Github.
8 changes: 8 additions & 0 deletions src/main/resources/net/nicoulaj/idea/markdown/preview.css
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,11 @@
caption-side: top;
text-align: center;
}

#markdown-preview del {
text-decoration: line-through;
}

#markdown-preview p del {
text-decoration: line-through;
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
<option name="FONT_TYPE" value="2"/>
</value>
</option>
<option name="MARKDOWN.STRIKETHROUGH">
<value>
<!--<option name="FOREGROUND" value=""/>-->
<!--<option name="BACKGROUND" value=""/>-->
<option name="EFFECT_TYPE" value="3" />
</value>
</option>
<!-- <option name="MARKDOWN.IMAGE">
<value>
<option name="FOREGROUND" value=""/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
<option name="FONT_TYPE" value="2"/>
</value>
</option>
<option name="MARKDOWN.STRIKETHROUGH">
<value>
<!--<option name="FOREGROUND" value=""/>-->
<!--<option name="BACKGROUND" value=""/>-->
<option name="EFFECT_TYPE" value="3" />
</value>
</option>
<!-- <option name="MARKDOWN.IMAGE">
<value>
<option name="FOREGROUND" value=""/>
Expand Down

0 comments on commit 98d1543

Please sign in to comment.