How can I wrap my markdown in an HTML div?
Markdown
For Markdown, This is by design. From the Inline HTML section of the Markdown reference:
Note that Markdown formatting syntax is not processed within block-level HTML tags. E.g., you can’t use Markdown-style emphasis inside an HTML block.
But it is explicitly allowed for span-level tags:
Unlike block-level HTML tags, Markdown syntax is processed within span-level tags.
So, depending on your use-case, you might get away with using a span
instead of a div
.
CommonMark
If the library you use implements CommonMark, you are lucky. Example 108 and 109 of the spec show that if you keep an empty line in between the HTML block and the markdown code, the contents will be parsed as Markdown:
<div>
*Emphasized* text.
</div>
should work, while the following shouldn't:
<div>
*Emphasized* text.
</div>
And, again according to the same section in the reference, some implementations recognize an additional markdown=1
attribute on the HTML tag to enable parsing of Markdown inside it.
Though it doesn't seem to work in StackOverflow yet:
Testing **Markdown** inside a red-background div.Markdown scoping with section and div blocks?
Yep, that's by design. According to Gruber:
Note that Markdown formatting syntax is not processed within block-level HTML tags. E.g., you can’t use Markdown-style *emphasis* inside an HTML block.
I'm not aware of any sort of workaround for that, but I wouldn't put myself at guru-level when it comes to Markdown.
Edit: You might want to check out PHP Markdown Extra if you're working with PHP.
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.
Wrapping plots in another html container within an Rmd file
Here is one way to do it.
- First, we create a chunk hook to wrap chunk output inside a tag.
- We pass
wrap = div
as chunk option to wrap insidediv
. - Set
out.extra = ""
to foolknitr
into outputting html for plot output. Note that this is required only fordiv
tag and not forspan
, as markdown is parsed insidespan
tag.s
DONE!
Here is a gist with Rmd, md and html files, and here is the html preview
## knitr Chunk Hook to Wrap
```{r setup, echo = F}
knit_hooks$set(wrap = function(before, options, envir){
if (before){
paste0('<', options$wrap, '>')
} else {
paste0('</', options$wrap, '>')
}
})
```
```{r comment = NA, echo = F, wrap = 'div', out.extra=""}
plot(mtcars$mpg, mtcars$wt)
```
Wrap HTML structure around an existing HTML element using jQuery
In the plugin you can replace the textarea with the template and then add the textarea back to the element
(function($) {
var template = '<div class="uk-htmleditor-content">\ <div class="editor-toolbar">\ // buttons here\ </div>\ <div class="editor-code">\ \ </div>\ <div class="editor-preview">\ <div>Markdown parsed from left panel into HTML preview in this right panel</div>\ </div>\</div>';
$.fn.markdownEditor = function() { return this.each(function() { var $ct = $(template); $(this).replaceWith($ct); $ct.find('.editor-code').append(this); }); };})(jQuery);
$('.markdown-editor-textarea').markdownEditor();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><textarea class="markdown-editor-textarea"></textarea>
Related Topics
Add Border to Div Increase Div Width
Display Background Color for The Page & Align Texts at Center
Streaming a Video from Google Drive Using HTML5 Video Tag
Detecting Real Time Window Size Changes in Angular 4
How to Remove The Default Link Color of The HTML Hyperlink 'A' Tag
How to Make Image Caption Width to Match Image Width
CSS Filter Not Working in Firefox
How to Hide Autofill Safari Icon in Input Field
How to Avoid Flash of Unstyled Text (Fout) Even with Web Font Loader
Add Spacing Between Vertically Stacked Columns in Bootstrap 4
How to Change Svg Color When It Is an Encoded CSS Background Image
Svg Lineargradient Hidden If Svg Is Hidden in Seperate Class
Method to Convert HTML5 Canvas to Svg
Content Url Is Not Working in Firefox
While Display Image Crop Top and Bottom of Image Using CSS