JavaScript Wrap markdown in appropriate HTML with JavaScript

Sounds like a neat project.

If you're using content-editable, and you want to update the user's input as they're typing, you'll probably need to dive into some fairly gnarly stuff, especially if you want to support IE.

I've actually written two very small libraries Caret and Wysiwyg that could help, take a look at the samples for each.

You can use Caret to watch the user's input, and then use Wysiwyg to do things like wrap the line in an h1 tag. The line wrapping is a little tricky, you can probably look at Caret's source for some hints though.

Even if you don't use either library, they should get you started.

Answer:1

In my understanding, you are trying to create a Markdown editor with a kind of syntax highlighting. I like the idea but I think there is no such thing already existing. Markdown is designed to be "easy-to-read/easy-to-write" enough to avoid having to use a complex editor. Pagedown for instance is a bit inimical to this principle (even if it's a great tool).

Anyway, if you want to implement that yourself you will have multiple choices:

  • Upstream of the markdown converter by changing

    # My H1
    

    to

    # # My H1
    
  • Downstream of the markdown converter by changing

    <h1>My H1</h1>
    

    to

    <h1># My H1</h1>
    

    But that's not the preferred way since Markdown is not bijective, I guess you don't want to have this kind of conversion:

    My H1
    =====
    

    to

    <h1># My H1</h1>
    
  • Modify the markdown converter if you have access to the source code or create your own one.

In any case you will have to be fluent in regular expressions.

Answer:2

if you are dealing with a well formed DOM - look into jquery's wrap functions

.wrap()
.wrapAll()
.wrapInner()
Answer:3

Use Case : I have a webpage which shows popovers for some of the functionalities. The popovers can be considered to be a HTML div which is shown when the corresponding button is clicked. And again go ...

Use Case : I have a webpage which shows popovers for some of the functionalities. The popovers can be considered to be a HTML div which is shown when the corresponding button is clicked. And again go ...

  1. change browser back button url
  2. change browser back button behaviour
  3. change browser back to english
  4. change browser back to google
  5. change browser back
  6. javascript change browser back button behavior
  7. change default browser back to internet explorer
  8. change google browser back to english
  9. change my browser back to english
  10. php change browser back button
  11. javascript change browser back button
  12. change default browser back

If you render the code below in chrome, you will see this adds fine but if you use IE, the rows doesn't get added. Could you tell me what am I doing wrong here that its not working in IE? When I add a ...

If you render the code below in chrome, you will see this adds fine but if you use IE, the rows doesn't get added. Could you tell me what am I doing wrong here that its not working in IE? When I add a ...

  1. javascript works in chrome but not ie
  2. javascript works on chrome but not firefox
  3. javascript works in chrome but not internet explorer
  4. javascript works on chrome not ie
  5. javascript works in chrome but not edge
  6. javascript works in chrome debugger
  7. javascript only works in chrome

could not find a solution to my problem so i'll ask here. When i insert jQuery file, i get an error on line 2: unexpected token ILLEGAL Code: jQuery(document).ready(function(){ $('body').append(...

could not find a solution to my problem so i'll ask here. When i insert jQuery file, i get an error on line 2: unexpected token ILLEGAL Code: jQuery(document).ready(function(){ $('body').append(...

  1. jquery unexpected token ' '
  2. jquery unexpected token in json at position 0
  3. jquery unexpected token in json
  4. jquery unexpected token var
  5. jquery unexpected token export
  6. jquery unexpected token if
  7. jquery unexpected token in json at position
  8. jquery unexpected token else
  9. jquery unexpected token function
  10. jquery unexpected token o in json
  11. jquery unexpected token string literal
  12. jquery unexpected token illegal
  13. jquery unexpected token o
  14. jquery unexpected token html
  15. jquery unexpected token array
  16. jquery ajax unexpected token
  17. jquery syntaxerror unexpected token
  18. jquery parsejson unexpected token
  19. jquery ui unexpected token
  20. jquery unexpected token identifier

For my project i need google maps api. I just can serve the api via script tag, so i tried something like that. my html: <head> <title>app</title> <script type="text/...

For my project i need google maps api. I just can serve the api via script tag, so i tried something like that. my html: <head> <title>app</title> <script type="text/...

  1. google maps with weather
  2. google maps with county lines
  3. google maps with traffic
  4. google maps with street view
  5. google maps with compass
  6. google maps with property lines
  7. google maps with addresses
  8. google maps with multiple stops
  9. google maps with pictures
  10. google maps with elevation
  11. google maps with coordinates
  12. google maps with zip codes
  13. google maps with directions
  14. google maps with time
  15. google maps with pins
  16. google maps with radius
  17. google maps with tolls
  18. google maps with topography
  19. google maps with time zones
  20. google maps with speed limits