GithubHelp home page GithubHelp logo

bevacqua / woofmark Goto Github PK

View Code? Open in Web Editor NEW
1.6K 32.0 74.0 3.96 MB

:dog2: Barking up the DOM tree. A modular, progressive, and beautiful Markdown and HTML editor

Home Page: https://bevacqua.github.io/woofmark

License: MIT License

CSS 8.33% JavaScript 88.18% HTML 3.48%
front-end javascript vanilla markdown markdown-editor

woofmark's Introduction

woofmark

Barking up the DOM tree. A modular, progressive, and beautiful Markdown and HTML editor

Browser support includes every sane browser and IE9+.

Demo

woofmark-stompflow

Try out the demo!

Features

  • Small and focused
  • Progressive, enhance a raw <textarea>
  • Markdown, HTML, and WYSIWYG input modes
  • Text selection persists even across input modes!
  • Built in Undo and Redo
  • Entirely customizable styles
  • Bring your own parsers

Look and feel is meant to blend into your designs

Install

You can get it on npm.

npm install woofmark --save

Or bower, too.

bower install woofmark --save

woofmark.find(textarea)

Returns an editor object associated with a woofmark instance, or null if none exists for the textarea yet. When woofmark(textarea, options?) is called, woofmark.find will be used to look up an existing instance, which gets immediately returned.

woofmark(textarea, options?)

Adds rich editing capabilities to a textarea element. Returns an editor object.

options.parseMarkdown

A method that's called by woofmark whenever it needs to parse Markdown into HTML. This way, editing user input is decoupled from a Markdown parser. We suggest you use megamark to parse Markdown. This parser is used whenever the editor switches from Markdown mode into HTML or WYSIWYG mode.

woofmark(textarea, {
  parseMarkdown: require('megamark')
});

For optimal consistency, your parseMarkdown method should match whatever Markdown parsing you do on the server-side.

options.parseHTML

A method that's called by woofmark whenever it needs to parse HTML or a DOM tree into Markdown. This way, editing user input is decoupled from a DOM parser. We suggest you use domador to parse HTML and DOM. This parser is used whenever the editor switches to Markdown mode, and also when .value() is called while in the HTML or WYSIWYG modes.

woofmark(textarea, {
  parseHTML: require('domador')
});

If you're implementing your own parseHTML method, note that woofmark will call parseHTML with either a DOM element or a Markdown string.

While the parseHTML method will never map HTML back to the original Markdown in 100% cases, (because you can't really know if the original source was plain HTML or Markdown), it should strive to detokenize whatever special tokens you may allow in parseMarkdown, so that the user isn't met with inconsistent output when switching between the different editing modes.

A test of sufficiently good-citizen behavior can be found below. This is code for "Once an input Markdown string is parsed into HTML and back into Markdown, any further back-and-forth conversions should return the same output." Ensuring consistent back-and-forth is ensuring humans aren't confused when switching modes in the editor.

var parsed = parseHTML(parseMarkdown(original));
assert.equal(parseHTML(parseMarkdown(parsed)), parsed);

As an example, consider the following piece of Markdown:

Hey @bevacqua I _love_ [woofmark](https://github.com/bevacqua/woofmark)!

Without any custom Markdown hooks, it would translate to HTML similar to the following:

<p>Hey @bevacqua I <em>love</em> <a href="https://github.com/bevacqua/woofmark">woofmark</a>!</p>

However, suppose we were to add a tokenizer in our megamark configuration, like below:

woofmark(textarea, {
  parseMarkdown: function (input) {
    return require('megamark')(input, {
      tokenizers: [{
        token: /(^|\s)@([A-z]+)\b/g,
        transform: function (all, separator, id) {
          return separator + '<a href="/users/' + id + '">@' + id + '</a>';
        }
      }]
    });
  },
  parseHTML: require('domador')
});

Our HTML output would now look slightly different.

<p>Hey <a href="/users/bevacqua">@bevacqua</a> I <em>love</em> <a href="https://github.com/bevacqua/woofmark">woofmark</a>!</p>

The problem is that parseHTML doesn't know about the tokenizer, so if you were to convert the HTML back into Markdown, you'd get:

Hey [@bevacqua](/users/bevacqua) I _love_ [woofmark](https://github.com/bevacqua/woofmark)!

The solution is to let parseHTML "know" about the tokenizer, so to speak. In the example below, domador is now aware that links that start with @ should be converted back into something like @bevacqua.

woofmark(textarea, {
  parseMarkdown: function (input) {
    return require('megamark')(input, {
      tokenizers: [{
        token: /(^|\s)@([A-z]+)\b/g,
        transform: function (all, separator, id) {
          return separator + '<a href="/users/' + id + '">@' + id + '</a>';
        }
      }]
    });
  },
  parseHTML: function (input) {
    return require('domador')(input, {
      transform: function (el) {
        if (el.tagName === 'A' && el.innerHTML[0] === '@') {
          return el.innerHTML;
        }
      }
    });
  }
});

This kind of nudge to the Markdown compiler is particularly useful in simpler use cases where you'd want to preserve HTML elements entirely when they have CSS classes, as well.

Preserving Selection Across Input Modes

Note that both megamark and domador support a special option called markers, needed to preserve selection across input modes. Unless your parseHTML function supports this option, you'll lose that functionality when providing your own custom parsing functions. That's one of the reasons we strongly recommend using megamark and domador.

options.fencing

Prefers to wrap code blocks in "fences" (GitHub style) instead of indenting code blocks using four spaces. Defaults to true.

options.markdown

Enables Markdown user input mode. Defaults to true.

options.html

Enables HTML user input mode. Defaults to true.

options.wysiwyg

Enables WYSIWYG user input mode. Defaults to true.

options.defaultMode

Sets the default mode for the editor.

options.storage

Enables this particular instance woofmark to remember the user's preferred input mode. If enabled, the type of input mode will be persisted across browser refreshes using localStorage. You can pass in true if you'd like all instances to share the same localStorage property name, but you can also pass in the property name you want to use, directly. Useful for grouping preferences as you see fit.

Note that the mode saved by storage is always preferred over the default mode.

options.render.modes

This option can be set to a method that determines how to fill the Markdown, HTML, and WYSIWYG mode buttons. The method will be called once for each of them.

Example
woofmark(textarea, {
  render: {
    modes: function (button, id) {
      button.className = 'woofmark-mode-' + id;
    }
  }
});

options.render.commands

Same as options.render.modes but for command buttons. Called once on each button.

options.images

If you wish to set up file uploads, in addition to letting the user just paste a link to an image (which is always enabled), you can configure options.images like below.

{
  // http method to use, defaults to PUT
  method: 'PUT',

  // endpoint where the images will be uploaded to, required
  url: '/uploads',

  // image field key, passed to bureaucracy, which defaults to 'uploads'
  fieldKey: 'uploads',

  // optional additional form submission data, passed to `bureaucracy`
  formData: { description: 'A new image' },

  // optional options for `xhr` upload request, passed to `bureaucracy`
  xhrOptions: { headers: {} },

  // optional text describing the kind of files that can be uploaded
  restriction: 'GIF, JPG, and PNG images',

  // should return whether `e.dataTransfer.files[i]` is valid, defaults to a `true` operation
  validate: function isItAnImageFile (file) {
    return /^image\/(gif|png|p?jpe?g)$/i.test(file.type);
  }
}

woofmark expects a JSON response including a results property that's an array describing the success of each file upload. Each file's entry should include an href and a title:

{
  results: [
    { href: '/images/new.jpg', title: 'New image' }
  ]
}

For more information on file uploads, see bureaucracy.

options.attachments

Virtually the same as images, except an anchor <a> tag will be used instead of an image <img> tag.

To set the formatting of the inserted attachment link, set options.mergeHtmlAndAttachment; the default follows this format:

function mergeHtmlAndAttachment (chunks, link) {
  var linkText = chunks.selection || link.title;
  return {
    before: chunks.before,
    selection: '<a href="' + link.href + '">' + linkText + '</a>',
    after: chunks.after,
  };
}

editor

The editor API allows you to interact with woofmark editor instances. This is what you get back from woofmark(textarea, options) or woofmark.find(textarea).

editor.addCommand(combo, fn)

Binds a keyboard key combination such as cmd+shift+b to a method using kanye. Please note that you should always use cmd rather than ctrl. In non-OSX environments it'll be properly mapped to ctrl. When the combo is entered, fn(e, mode, chunks) will be called.

  • e is the original event object
  • mode can be markdown, html, or wysiwyg
  • chunks is a chunks object, describing the current state of the editor

In addition, fn is given a this context similar to that of Grunt tasks, where you can choose to do nothing and the command is assumed to be synchronous, or you can call this.async() and get back a done callback like in the example below.

editor.addCommand('cmd+j', function jump (e, mode, chunks) {
  var done = this.async();
  // TODO: async operation
  done();
});

When the command finishes, the editor will recover focus, and whatever changes where made to the chunks object will be applied to the editor. All commands performed by woofmark work this way, so please take a look at the source code if you want to implement your own commands.

editor.addCommandButton(id, combo?, fn)

Adds a button to the editor using an id and an event handler. When the button is pressed, fn(e, mode, chunks) will be called with the same arguments as the ones passed if using editor.addCommand(combo, fn).

You can optionally pass in a combo, in which case editor.addCommand(combo, fn) will be called, in addition to creating the command button.

editor.runCommand(fn)

If you just want to run a command without setting up a keyboard shortcut or a button, you can use this method. Note that there won't be any e event argument in this case, you'll only get chunks, mode passed to fn. You can still run the command asynchronously using this.async(). Note that the argument order chunks, mode is the reverse of that passed to addCommand (mode, chunks).

editor.parseMarkdown()

This is the same method passed as an option.

editor.parseHTML()

This is the same method passed as an option.

editor.destroy()

Destroys the editor instance, removing all event handlers. The editor is reverted to markdown mode, and assigned the proper Markdown source code if needed. Then we go back to being a plain old and dull <textarea> element.

editor.value(text)

If optional Markdown string text is provided, it is used to overwrite the current editor content, parsing into HTML if necessary. Regardless of whether text is provided, value() returns the current Markdown value for the editor.

editor.editable

If options.wysiwyg then this will be the contentEditable <div>. Otherwise it'll be set to null.

editor.mode

The current mode for the editor. Can be markdown, html, or wysiwyg.

editor.setMode(mode)

Sets the current mode of the editor.

editor.showLinkDialog()

Shows the insert link dialog as if the button to insert a link had been clicked.

editor.showImageDialog()

Shows the insert image dialog as if the button to insert a image had been clicked.

editor.showAttachmentDialog()

Shows the insert attachment dialog as if the button to insert a attachment had been clicked.

editor.history

Exposes a few methods to gain insight into the operation history for the editor instance.

editor.history.undo()

Undo the last operation.

editor.history.redo()

Re-applies the most recently undone operation.

editor.history.canUndo()

Returns a boolean value indicating whether there are any operations left to undo.

editor.history.canRedo()

Returns a boolean value indicating whether there are any operations left to redo.

chunks

Please ignore undocumented functionality in the chunks object.

Describes the current state of the editor. This is the context you get on command event handlers such as the method passed to editor.runCommand.

Modifying the values in a chunks object during a command will result in changes to the user input in such a way that Undo and Redo can be taken care of automatically on your behalf, basically by going back to the previous (or next) chunks state in the editor's internal history.

chunks.selection

The currently selected piece of text in the editor, regardless of input mode.

chunks.before

The text that comes before chunks.selection in the editor.

chunks.after

The text that comes after chunks.selection in the editor.

chunks.scrollTop

The current scrollTop for the element. Useful to restore later in action history navigation.

chunks.trim(remove?)

Moves whitespace on either end of chunks.selection to chunks.before and chunks.after respectively. If remove has been set to true, the whitespace in the selection is discarded instead.

woofmark.strings

To enable localization, woofmark.strings exposes all user-facing messages used in woofmark. Make sure not to replace woofmark.strings with a new object, as a reference to it is cached during module load.

Usage with horsey

See banksy to integrate horsey into woofmark.

License

MIT

woofmark's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

woofmark's Issues

set scrollTop on mode change

I find that when i switch modes, the browser scroll position (document.body.scrollTop) shifts, which is disorienting. Any interest in saving and/or adjusting for the scroll position when changing modes? I've tested this in my own code by storing scrollTop before the change and then setting it after the change.

Selecting a bit of text and then pressing bold, italic, bold, ruins the selection.

Type the following into a fresh instance of the editor in chrome:

This is a test line.

Then, using the keyboard or mouse, select the entire line. Press the bold button, followed by the italic button, and then the bold button again.

The resulting selection will now be:

This is a t

and subsequent presses of the bold and italic buttons do odd things (either causing the selection to reduce in size again, disappear, or do absolutely nothing).

I would expect the text selection to remain the same regardless of how many times the bold and or italic buttons are pressed in this situation. The same thing happens if the shortcut keys for bold and italic are used.

Depending on which browser is used, depends on how much of the text selection is changed. I have tested this on both the demo site (https://bevacqua.github.io/woofmark/), and a version I downloaded from npm (version 4.2.3).

Running on chrome:
woofmarkbolditalic

Link insertion bugs

Hello! Looks like I've found a couple of bugs all of them having to do with link insertion into a fresh instance of woofmark.

When you try to insert a link (http://bevacqua.github.io/woofmark/) in wysiwyg with text link:

link 
//bugs start here with only the first letter being linked

and then switch to markdown:

[l][1]ink

[1]: http://bevacqua.github.io/woofmark/

html:

<p>/</p>

and back to wysiwyg you finally get this:

/

The same happens if you try to insert a link in markdown mode. Somehow that doesn't happen if you not only insert a link, but also write a word on another line (while if you start from wysiwyg mode, you still get only the first letter linked).

If your first line in markdown is a URL starting with http, then this is what you get in html:

<p></p>

which, of course, translates to nothing in wysiwyg.

"clear formatting" button or tool

This seems like it'd be pretty easy to implement with a runCommand but it's also a fairly common thing to want. Any interest in including this in a standard tool set?

Change html in the buttons

How can i change the displayed value in the command buttons or to remove some buttons entirely?

For example:

  • change UL button icon into text '<UL>'
  • i enabled only 1 mode in editor - markdown, so displaying markdown button in not needed anymore.

Buttons above the wysiwyg-container?

Doesn't seem to be possible (by config) to render the buttons (in the DOM) above the wysiwyg-container?

I could do this using CSS and flexbox or "display: table" but it will make other this more complex, like "inlining" the buttons next to each other.

Question: How can I remove inline styles on paste?

I want to be able to use woofmark as a wysiwyg editor for markdown only.

  1. I never want my users to be able to switch to html mode (I know how to do this).
  2. I would like to automatically strip out any inline styles when a user pastes rich text into the editor while in wysiwyg mode. ( don't know how to do this).

How can I accomplish the second item?

I created a code pen to illustrate the non-desirable behavior. http://codepen.io/jessegavin/pen/mRyOJb?editors=0010

Thanks so much. This is one of the coolest implementations I have seen for a wysiwyg editor.

React.js

Is it a good idea to get it working with React.js given that we'd be dealing with a virtual DOM?

inserting options.images.formData for upload handling

Hi, I'm hoping for some guidance on where to put this code most efficiently; not a high priority though. Related to bevacqua/bureaucracy#2

I found that bureaucracy is in prompts/prompt.js and there's an opportunity to pass in an options object here:

var bureaucrat = bureaucracy.setup(domup.fileinput, {
method: upload.method,
formData: upload.formData,
fieldKey: upload.fieldKey,
xhrOptions: upload.xhrOptions,

To link that to the options object in the woofmark constructor, looks like changes would be needed in these two lines (for two modes):

(options.prompts[type] || options.prompts.link)(options, once(resolved));

(options.prompts[type] || options.prompts.link)(options, once(resolved));

...then we can access editor.options on this line, passing it to linkOrImageOrAttachment():

editor.linkOrImageOrAttachment(type, files).call(this, mode, chunks);

If that looks good, I can do up a PR -- again, not super urgent. Thanks.

HTML mode content get wrapped in <p> tags upon every refresh

I think I've found another bug using the editor. The resulted text is not consistent refreshing the page with text in HTML mode.

I'm using Firefox Nightly 41,

Problem:
Texts unexpected appended to editor upon refresh

Expected Result:
<h1>Heading Text</h1> be consistent.

Actual Result:
First time refresh: <p><h1>Heading Text</h1></p>
Second time refresh: <p><p><h1>Heading Text</h1></p></p>

Procedures:
Input any text into HTML mode, refresh page.

Analysis:
The content is not consistent. <p> tags is being prepended and appended upon every refresh in HTML mode.

A more complete example?

I'm trying to switch to woofmark from tinymce (to also support markdown...)

Unfortunately, I find it hard to to do my customizing based on the examples I found so far (here and under public lab). Maybe I'm looking in the wrong place but I'm looking for things like:

  • place commands & modes above the text editor
  • place images inline as base64

So far I managed to beautify the commands and modes using the render feature and fontawesome - but that really was a lot (too much) trial and error...

Any help is appreciated!

Calling formatting command

Hi, bevacqua

Could you please provide an example of how to execute formatting command without using .wk-commands? I have read the doc and still could not solve the problem.

Thank you very much.

Provide strikethrough function

The interface does not currently appear to permit a strikethrough function.
This would be incredibly useful, and is present on most comparable editors.

Provide tick list function

It would be highly useful to tick list (checklist), in addition to the existing bulleted and numbered lists.
This list would enable items listed in it to marked as done, or not done, by virtue of a tick (check mark).

*ashamed* I don't get the original textarea to sync with woofmark

Hola, I just stumbled over woofmark last night, and so far I like it.

But I can't figure out how to sync those. I mean, when submitting the form, nothing get posted..?
This is my js to init woofmark..

var rte = document.querySelector('.rich-text');
    woofmark(rte, {
        parseMarkdown: megamark,
        parseHTML: domador,
        defaultMode: 'wysiwyg'
    });

Use case, I want to provide an easy (wysiwyg) forum input but behind the scenes everything should be markdown. Do I need parseMarkdown and parseHTML for this?
Maybe I should learn more vanilla-js..

Saludos, Can

delete key on empty textarea in wysiwyg mode does not clear formatting tags in some cases

I've found a small issue I'm able to reproduce if:

  1. HTML (an h1) already exists at load-time in the .wk-wysiwyg element (wysiwyg mode)
  2. All content in the contentEditable div is selected and deleted
  3. Delete key is hit once again to leave the div completely empty
  4. New text is typed into the div
  5. h1 text appears, not plain p text

Note that to clear this formatting, you can click outside the div and click back in. This makes me think that there's some preserved formatting state in this (chromium) contentEditable which is cleared when it loses focus.

You can try it here: https://publiclab.github.io/PublicLab.Editor/examples/

Although I'm not able to reproduce it on the default demo at https://bevacqua.github.io/woofmark/ -- and I'm wondering if there's something about the interaction of the stylesheets with the contentEditable that causes it in one demo but not another.

Nested list issue when switching to - from markdown

In the Demo If I have:

<ol>
  <li>1
    <ol>
      <li>1.a</li>
    </ol>
  </li>
  <li>2</li>
</ol>

and switch to markdown then back to wysiwyg it looses the nested <ol> wrapper.
ex.

<ol>
  <li>1</li>
  <li>1.a</li>
  <li>2</li>
</ol>

Config option for non-footnoted image markdown: ![a.jpg](/a.jpg)

Current default in markdown mode is to insert:

![image description][1]

Then at the bottom of the doc:

[1]: http://url.com/image.jpg "image.jpg"

This is well-formed markdown but for many purposes this disrupts page flow - for example in inline-markdown-editor which is using woofmark for subsections of a larger document.

I'd like to propose that the default be the all-inline, all-one-line version:

![image.jpg](http://url.com/image.jpg)

Failing that, that we at least allow configuration of this.

Where is this code living? Would it be in megamark config, or bureaucracy? Or can we set this in Woofmark alone?

Thanks!

When creating a list, selecting bold (or italic) when no text has been written yet causes the list to break.

Type the following into a fresh instance of the editor in chrome:

This is a point

Using the keyboard or mouse select the entire line. Press the numbered list button. Hit enter and a number 2 should appear below. Without typing anything, press the bold button. The text "strong text" gets inserted between the 1. list item and the 2. list item. Type:

This is another point

Then hit enter once. The 2. label will disappear. Hit enter again, the cursor will move to the next line but will be indented. You could keep doing this for ages and each time the cursor would move to the next line and be indented. However, instead of typing anything, hit enter on the empty line. The cursor will move inline with "This is another point". Hitting enter twice more will delete the entire list.

I would expect pressing the bold button on an empty line to not break the list. Anything after that is probably because the editor is in some sort of broken state but could probably be looked into as well.

I have tested this on both the demo site (https://bevacqua.github.io/woofmark/), and a version I downloaded from npm (version 4.2.3).

Running on chrome:
woofmarklistbold

Enhancement Request: Set the value of the editor using markdown

The way I picture this working is a function being added to the editor object like editor.setValue(markdownString).

This would internally check editor.mode and then either just insert the markdownString into the editor (if in markdown mode) or run editor.parseMarkdown(markdownString) and then either render or insert the resulting HTML string into the editor (if in html or wysiwyg mode respectively).

It also wouldn't hurt to make this an option to pass into the woofmark() function with a name like option.initialValue or something.

P.S. Thanks for this great extensible library.

Disappearing line-break

Bug:
The position of the cursor at the moment of switching the view changes the behaviour of the parser.

How to reproduce:

  1. Open markdown view
  2. Set cursor at the end of a line ending in 2 spaces (this should parse to a line-break)
  3. Open html or wysiwyg view
  4. Line-break is not applied
  5. Open markdown view: the 2 spaces are reduced to 1 space

A case in which the bug does not come up:

  1. Open markdown view
  2. Set cursor not at the end of a line ending in 2 spaces (this should parse to a line-break)
  3. Open html or wysiwyg view
  4. Line-break is applied as expected
  5. Open markdown view: the 2 spaces are still there as expected

Some questions :)

2015-06-16 4 33 33

I need some functions as below.

  1. the way to apply widget like facebook's mention ui
  2. text highlights in textarea (you can see a automatically highlighted name when you mention your friend’s name with “@“ in Facebook)

Does woofmark provide a way to do them?
Or do you have any plan to provide?

thank!

Package woofmark not found

I wanted to add woofmark to my project with Bower but when i tried
->
'Bower install woofmark --save' return Package woofmark not found

Did you forgot something or is it just a random bug ?

Less-than-carets are removed when event is triggered

The less-than caret followed by text is removed when you e.g. set some text to bold in wysiwyg mode.

E.g: in the demo, write "<e", and change some other text to bold.

Is there any possibility to preserve these when typed in?

Toolbar button state and toggling modes.

Great work, first of all! But got a couple of questions.

  1. Is it possible to have buttons reflect current state of a selection/cursor position? For example, if a bold text is selected or the cursor is within a bold text, then we can style the bold button as active.
  2. Is it possible to have formatting buttons toggle their state? For example, when in WSIWYG mode you click the bold button (or press the cmd+B shortcut) you get bold text, but you can't toggle it off by pressing the button or the shortcut for the second time.

[bug] unexcepted behavior and bug with codeblock

  1. add new codeblock in preview mode, then switch editor to markdown mode will cause error

default

  1. unexcepted behavior in html mode, when add new codeblock in preview mode repeatedly.
    (when click codeblock button twice, html tag should be switched create tag and remove tag, not create tags nested)

default

Ps: Enable to edit markdown in preview mode is awesome! I really love this editor!

YouTube <iframe> gone after switching to HTML or WYSIWYG mode

I have some contents that embeds YouTube videos in it with the YouTube iframe embed code. I thought it'd be a good idea to have woofmark previews it in the WYSIWYG mode but then it never appeared. Switching to HTML mode also shows that it's gone.

Markdown to HTML = iframe gone
Markdown to WYSIWYG = iframe gone
Start in HTML/WYSIWYG = iframe gone

Buttons feature request

I have some feature requests.

  1. Can you add an option to let the buttons render on top of the textarea?
  2. Can the buttons including custom ones get arranged for display? For example, bring the Heading buttons left, next to italic?

GFM Tables do not work properly

First of all, woofmark looks awesome! I think this would work great with our app.

I found a bug with tables however. Here are the steps to reproduce on the demo page http://bevacqua.github.io/woofmark/

Click markdown icon and paste the following

| col1 | col2 | col3 |
|------|------|------|
| foo  | bar  | baz  |
| food | bars | bats |

Click wysiwyg icon and you'll see a table (woohoo!) but without borders (boo)

col1 col2 col3
foo bar baz
food bars bats

Click html icon and you'll see proper html table (woohoo!)

<table>
<thead>
<tr><th>col1</th><th>col2</th><th>col3</th></tr>
</thead>
<tbody>
<tr><td>foo</td><td>bar</td><td>baz</td></tr>
<tr><td>food</td><td>bars</td><td>bats</td></tr>
</tbody>
</table>

Now click markdown icon and you'll get paragraphs?? (oops)

col1col2col3

foobarbaz

foodbarsbats

I'm assuming the html -> markdown doesn't support tables yet?

History code appearing upon refreshing page?

I have been testing the software and I think I've found a bug?

I'm using Firefox Nightly 41,

Problem:
Texts unexpected appended to editor upon refresh

Expected Text:
space

Resulted Text:
First time. spaceWoofmarkSelectionOpenMarkergbdhcWoofmarkSelectionCloseMarkergbdhc
Second time. spaceWoofmarkSelectionOpenMarkerecaacbhWoofmarkSelectionCloseMarkerecaacbh

Procedures:
Input space or any text into WYSIWYG mode, refresh page.

Analysis:
The string "WoofmarkSelectionOpenMarker" + code string + "WoofmarkSelectionCloseMarker" + repeated code string is appended to text upon every refresh on WYSIWYG mode with some text input.

Is this project active?

This markdown editor looks really good and i would like it to use in all my production websites, however i am concerned that not much activity is here for a while.

Is this still maintained? Issues resolved?

Is there any event triggered on text input?

The only way I've found to listen to the text input is to add event listener to woofmark.find(textarea).textarea and .editable objects.
Is there any other way of doing that?

Image and link prompt position

Is it possible, without changing the core code in my project, to custom the DOM node where the prompts for images and links are created?

Switching between WYSIWYG and Markdown mode breaks formating

Hey, I found some bugs with the markdown mode.

Bug 1

When marking text as bold in WYSIWYG Mode and then line breaking after it, the text gets rendered correctly. But when switching to markdown mode and back, the text formatting breaks and the * are shown and the text isn't rendered correctly anymore. (In our implementation you can see the * are escaped with \)

Bug 2

When marking text as bold in WYSIWYG mode and then adding text behind it and marking it as regular text, the rendering breaks when switching to markdown mode and back to WYSIWYG mode.

How can I add command button then render it?

I have the following code:

woofmark(document.querySelector('#ta'), {
        parseMarkdown: megamark,
        parseHTML: domador,
        render: {
            commands: function (button, id) {
                button.className = 'btn';
                var n = {
                    "bold": 'B',
                    "italic": 'I',
                    "quote": 'Q',
                    "code": 'C',
                    "ol": 'OL',
                    "ul": 'UL',
                    "heading": 'H',
                    "link": 'A',
                    "image": 'IMG'
                };
                button.innerHTML = n[id];
            },
            modes: function (button, id) {
                button.className = 'btn';
                var n = {
                    "markdown": "MarkDown",
                    "html": "HTML",
                    "wysiwyg": "WYSIWYG"
                }
                button.innerHTML = n[id];
            }
        }
    }).addCommandButton("Jump", function jump() {});

Is there is not a built-in way to render added command buttons? Or do I have to do it outside woofmark?

bureaucracy options set validate: 'image', failing non-image attachments

Finally got this bug!

This needs to be set to upload.validate || 'image', to properly set validator as in README: https://github.com/bevacqua/woofmark#optionsattachments.

https://github.com/bevacqua/woofmark/blob/master/src/prompts/prompt.js#L116

I also found that after solving that, I got options.mergeHtmlAndAttachment is not a function on this line:

parts = options.mergeHtmlAndAttachment(chunks.before + chunks.selection + chunks.after, link);

That's because that should be specified here:

mergeHtmlAndAttachment: options.mergeHtmlAndAttachment,

But that doesn't seem to appear anywhere else in the codebase. I think it could be from a previous version of the API, but it seems to be pretty simple:

options.mergeHtmlAndAttachment(chunks.before + chunks.selection + chunks.after, link);

And it expects:

      chunks.before = parts.before;
      chunks.selection = parts.selection;
      chunks.after = parts.after;

I'm going to try just adding a default that wraps it in an <a> tag.

Happy to submit a PR shortly.

image upload response needs to be parsed into JSON?

I'm responding (from Rails) to an image upload, and when I send a response back it's parsed as a string, not JSON, oddly. The headers seem right:

Cache-Control:max-age=0, private, must-revalidate
Connection:keep-alive
Content-Encoding:gzip
Content-Type:application/json; charset=utf-8
Date:Fri, 03 Jun 2016 18:14:26 GMT
ETag:W/"366c2e915957fbb3688349173c85b656"
Server:nginx/1.8.1 + Phusion Passenger 5.0.26
Set-Cookie:_session_id=546ca71df6549ce20171d258b9616027; path=/; HttpOnly
Status:200 OK
Transfer-Encoding:chunked
X-Powered-By:Phusion Passenger 5.0.26
X-Request-Id:39752ef745d8261da5eee350caa554a3
X-Runtime:5.814758
X-UA-Compatible:IE=Edge

And the response body is:

{"id":29,"url":"/system/images/photos/000/000/029/large/batman.gif","filename":"batman.gif","href":"/system/images/photos/000/000/029/large/batman.gif","title":"batman.gif"}

However, I had to add the following to line 180 of Woofmark's prompts/prompt.js to get body.href to return anything:

body = JSON.parse(body);

Do you think I'm doing something wrong in encoding my server response, and/or would adding an extra check and ability to parse into JSON be a useful extension to Woofmark's abilities?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.