Skip to content

Commit

Permalink
Add example markdown in the portal editor new section & fix MD view bug
Browse files Browse the repository at this point in the history
- Example document contains common markdown syntax examples and is pre-loaded in the text area of a new section
- Also fix a bug in markdownView where the highlightjs showdown extension was not loading even though `code` was present in the markdown

Closes issue #1104
  • Loading branch information
robyngit committed Sep 19, 2019
1 parent c5e335a commit 85452bd
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/js/models/portals/PortalModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ define(["jquery",
"models/CollectionModel",
"models/Search",
"models/filters/FilterGroup",
"models/Map"
"models/Map",
"text!templates/portals/editor/MarkdownExample.md",
],
/** @lends PortalModel.prototype */
function($, _, Backbone, gmaps, uuid, Filters, SolrResults, PortalSectionModel, PortalImage,
EMLParty, EMLText, CollectionModel, SearchModel, FilterGroup, MapModel) {
EMLParty, EMLText, CollectionModel, SearchModel, FilterGroup, MapModel, MarkdownExample) {
/**
* A PortalModel is a specialized collection that represents a portal,
* including the associated data, people, portal descriptions, results and
Expand Down Expand Up @@ -85,6 +86,11 @@ define(["jquery",
});
},

/**
* The default text to use in the markdown example in a new section
*/
markdownExample: MarkdownExample,

/**
* Overrides the default Backbone.Model.initialize() function to
* provide some custom initialize options
Expand Down Expand Up @@ -1238,7 +1244,7 @@ define(["jquery",
newSection.set({
label: newSectionLabel,
content: new EMLText({
markdown: "Add some content here.",
markdown: this.markdownExample,
type: "content"
})
});
Expand Down
48 changes: 48 additions & 0 deletions src/js/templates/portals/editor/MarkdownExample.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Replace this example with your content. Styling using markdown is supported.

# Level 1 Header

Markdown is a simple way to format text.

## Level 2 Header

For example, *this text will be italic* and **this text will be bold**. Here is a link to [DataOne](https://www.dataone.org), and here is an equation written using the TeX language: $$ y =X\beta + \epsilon $$.

Add an image like so: ![DataOne logo](https://www.dataone.org/sites/default/files/d1-logo-v8_aligned_left.png)

Show in-line code using `single backticks`, or show it as a separate block using triple backticks:

```r
my_string <- "Check out the code I wrote"
print(my_string)
```

Here is how to make a table:
| Tables | Are | Cool |
| ------ | --- | ----- |
| x | a | $1600 |
| y | b | $12 |
| z | c | $1600 |

The following is an unordered list:
* List item a
* List item b
* List item c
* You can create nested lists by indenting list items by four spaces.
* Sub-item 2

This is a numbered list:
1. First
2. Second
3. Third

To quote some text, just start a line with a `>` character. In the words of Grace Hopper:
> information is more valuable than the hardware which processes it.
You can even add emojis :smile:!

### More help with markdown

- [Markdown reference](https://commonmark.org/help/)
- [Ten minute tutorial](https://commonmark.org/help/tutorial/)
- For a longer example where you can also preview the results, checkout the [Showdown Live Editor](http://demo.showdownjs.com/)
2 changes: 1 addition & 1 deletion src/js/views/MarkdownView.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ define([ "jquery", "underscore", "backbone",
// ===== the regular expressions used to test whether showdown extensions are required ===== //
// note: these expressions test the *markdown* and *not* the html

var regexHighlight = new RegExp("'.*'"), // too general?
var regexHighlight = new RegExp("`.*`"), // too general?
regexDocbook = new RegExp("<(title|citetitle|emphasis|para|ulink|literallayout|itemizedlist|orderedlist|listitem|subscript|superscript).*>"),
// for bootstrap: test for tables, directly from showdown/src/subParsers/makehtml/tables.js
// if we add more bootstrap classes, this will become more complicated since we have to test the markdown before the initial parse
Expand Down

0 comments on commit 85452bd

Please sign in to comment.