Grunt Inline CSS and Javascript - tumblr

Short Version:
Is there a way, using Grunt, to include minified CSS and JavaScript inline?
To use usemin's formatting as an example, I would like to see something like this:
<!-- build:css inline -->
<link rel="stylesheet" href="styles/foo.css">
<link rel="stylesheet" href="styles/bar.css">
...
<!-- endbuild -->
<!-- build:js inline -->
<script src="js/foo.js"></script>
<script src="js/bar.js"></script>
...
<!-- endbuild -->
Turned into this something like this:
<style>body { color: red; } /*css is here*/</style>
<script>var foo = 1; bar = 'some javascript code is here'; ...</script>
Long Version:
So, I'm working on a Tumblr theme. In order to use CSS or JS files in a theme, they have to be uploaded to Tumblr. The only way to upload is a crappy little web form that often crashes. I'm trying to avoid this interface until I'm ready to upload the final code because
there's no way to delete uploaded files, and
while I'm in the middle of development, these extra steps take too much time
To get this, I've been copying my CSS and JS into <style> and <script> tags in my file, then copying the whole thing into the Tumblr theme editor. It's faster, so I'm happy with that, but manually copying and pasting CSS and JS into a file seems to go against the spirit of Grunt and the automation it provides.
Ideally, I would be able to run grunt build and have it spit out an html file with the CSS and JS inline, then I can just copy that into the Tumblr interface (well, ideally, I would be able to copy that HTML file to Tumblr, but Tumblr doesn't provide FTP or SSH or any useful interface, so I'll settle for this).
It seemed like grunt-usemin could provide the functionality I'm looking for, but I haven't been able to get it working as I described. Maybe it's only made to put everything into a separate file.
I'm open to using any Grunt tool if anyone knows of one that could accomplish this.

I've used this one before: https://github.com/motherjones/grunt-html-smoosher. It's very straightforward, just provide an input file and output file; no extra configuration, it just finds the files automatically and inlines them.
grunt.initConfig({
smoosher: {
dist: {
files: {
'dest-index.html': 'source-index.html',
},
},
},
});
Hope this helps.

Just providing other references that might be useful:
This grant-inline task do inline css and javascripts but you can do it selective using the _inline parameter. There is also a similar task grunt-inline-assests that do same thing. Both are good to generate HTML e-mails.
Finally, the purpose of this one is a bit different; it inserts all your css and js as externals based on a tag in your HTML. This can be very useful when developing themes and front-ends where you want to have you js or css contained in many small files to easy maintenance. Sails-linker task can be used to inject all css and js while in development and one of the inliners above can be used to generate the final production HTML file with CSS and JS minified and inlined.

Related

How to get the whole code of a HTML element in Developer tools?

I'm looking for possibility to export or just copy the whole code of a HTML element, targeted with Developer Tools. With whole code I mean not only HTML (this option is good visible in context menu), but corresponding CSS and JS code too.
I found a Chrome extension, which claims to copy HTML and CSS, but it isn't reliable in its core function and doesn't copy JS at all.

HTML5 Ad made with Google webdesigner to Doubleclick for publishers Small Business

How do I publish a HTML5-Ad in Doubleclick for publishers Small Business? Seems like I need to insert click-macros. But were do I insert them if it´s based on script-event?
Generally when you're uploading an HTML5 creative, there are multiple files you are generally dealing with (CSS, JS, images, etc - along with the actual HTML file). The procedure is generally as follows:
1) DFP requires your creative assets (images, scripts, CSS etc) to be uploaded individually (Alternatively, the CSS and Javascript can be added inline into the HTML5 code).
2) The source code of your HTML file must be added to the "Code snippet" area.
3) Next, every file path in your creative code needs to be replaced by DFP file macros, which upon ad serving will be replaced by the absolute path url. If any file is referenced within a CSS or Javascript file, it will need to be brought/surfaced to the "Code Snippet", otherwise they won't be replaced by the actual paths.
So if your original HTML source has an img tag like this:
<img src="product1.jpg"/>
You need to pre-upload product1.jpg into DFP and change that img src to reference the DFP name for this file using the macro. Thus it may end up looking like this:
<img src="%%FILE:JPG1%%"/>
But if you are using SVG images, you cannot currently use the macro in this way. You'll need to either host the SVG files externally and reference with a full path to them (ie: <img src="http://someserver/file.svg">) or you can paste the contents of the SVG file in-line.
BR,
Bablu Chakma

PhpStorm code completion and non physical file path for CSS and JavaScript

Using minify, instead of including the individual CSS/JavaScript files directly, I have something like this in my HTML file:
<link rel="stylesheet" href="/min/g=css8" type="text/css"/>
Autocomplete for CSS or JavaScript doesn't work in this html.
I tried looking for ways to be able to specify the individual files to PhpStorm to use in autocomplete, but could not find any option. Suggestions?

How can I test what my readme.md file will look like before committing to github?

I am writing a readme for my github project in the .md format. Is there a way can I test what my readme.md file will look like before committing to github?
Many ways: If you're on a Mac, use Mou.
If you want to test in a browser, you could try StackEdit, as pointed out by #Aaron or Dillinger since Notepag seems to be down now. Personally I use Dillinger since it just works and saves all my documents in my browser's local database.
Atom works nicely out of the box - just open the Markdown file and hit Ctrl+Shift+M to toggle the Markdown preview panel next to it. It handles HTML and images also.
Visual Studio Code has the option to edit and preview md file changes. Since VS Code is platform independent, this would work for Windows, Mac and Linux.
To switch between views, press Ctrl+Shift+V in the editor. You can view the preview side-by-side (Ctrl+K V) with the file you are editing and see changes reflected in real-time as you edit.
Also...
Q: Does VS Code support GitHub Flavored Markdown?
A: No, VS Code targets the CommonMark Markdown specification using the markdown-it library. GitHub is moving toward the CommonMark specification.
The preview button is this:
More details here
This is a pretty old question, however since I stumbled upon it while searching the internet maybe my answer is useful to others.
I just found a very useful CLI tool for rendering GitHub flavored markdown: grip. It uses GitHub's API, thus renders quite well.
Frankly, the developer of grip, has a more elaborate answer on these very similar questions:
Is there a command line utility for rendering github flavored markdown?
What's the best way to edit GitHub's Readme.md?
This one has proven reliable for quite some time: http://tmpvar.com/markdown.html
I usually just edit it on the GitHub website directly and click "Preview" just above the editing window.
Perhaps that's a new feature that's been added since this post was made.
VS Code
Mac: Command + Shift + V
Windows: Ctrl + Shift + V
Detailed Instructions
Open the .md file in VS Code. With the file selected, use the keyboard shortcuts above.
In the web, use Dillinger. It's awesome.
I use a locally hosted HTML file to preview GitHub readmes.
I looked at several existing options, but decided to roll my own to meet the following requirements:
Single file
Locally hosted (intranet) URL
No browser extension required
No locally hosted server-side processing (for example, no PHP)
Lightweight (for example, no jQuery)
High fidelity: use GitHub to render the Markdown, and same CSS
I keep local copies of my GitHub repositories in sibling directories under a "github" directory.
Each repo directory contains a README.md file:
.../github/
repo-a/
README.md
repo-b/
README.md
etc.
The github directory contains the "preview" HTML file:
.../github/
readme.html
To preview a readme, I browse github/readme.html, specifying the repo in the query string:
http://localhost/github/readme.html?repo-a
Alternatively, you can copy the readme.html into the same directory as the README.md, and omit the query string:
http://localhost/github/repo-a/readme.html
If the readme.html is in the same directory as README.md, you don't even need to serve readme.html over HTTP: you can just open it directly from your file system.
The HTML file uses the GitHub API to render the Markdown in a README.md file. There's a rate limit: at the time of writing, 60 requests per hour.
Works for me in current production versions of Chrome, IE, and Firefox on Windows 7.
Source
Here's the HTML file (readme.html):
<!DOCTYPE html>
<!--
Preview a GitHub README.md.
Either:
- Copy this file to a directory that contains repo directories,
and then specify a repo name in the query string.
For example:
http://localhost/github/readme.html?myrepo
or
- Copy this file to the directory that contains a README.md,
and then browse to this file without specifying a query string.
For example:
http://localhost/github/myrepo/readme.html
(or just open this file in your browser directly from
your file system, without HTTP)
-->
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
<meta name="author" content="Graham Hannington"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>GitHub readme preview</title>
<link rel="stylesheet" type="text/css" href="http://primercss.io/docs.css"/>
<script type="text/javascript">
//<![CDATA[
var HTTP_STATUS_OK = 200;
var URL_API_GITHUB_RENDER_MARKDOWN = "https://api.github.com/markdown/raw";
var README_FILE_NAME = "README.md";
var readmeURL;
var queryString = location.search.substring(1);
if (queryString.length > 0) {
readmeURL = queryString + "/" + README_FILE_NAME;
} else {
readmeURL = README_FILE_NAME;
}
// Get Markdown, then render it as HTML
function getThenRenderMarkdown(markdownURL) {
var xhr = new XMLHttpRequest();
xhr.open("GET", markdownURL, true);
xhr.responseType = "text";
xhr.onload = function(e) {
if (this.status == HTTP_STATUS_OK) {
// Response text contains Markdown
renderMarkdown(this.responseText);
}
}
xhr.send();
}
// Use the GitHub API to render Markdown as HTML
function renderMarkdown(markdown) {
var xhr = new XMLHttpRequest();
xhr.open("POST", URL_API_GITHUB_RENDER_MARKDOWN, true);
xhr.responseType = "html";
xhr.onload = function(e) {
if (this.status == HTTP_STATUS_OK) {
document.getElementById("readme").innerHTML = this.response;
}
}
xhr.send(markdown);
}
window.onload = function() {
getThenRenderMarkdown(readmeURL);
}
//]]>
</script>
</head>
<body>
<header class="masthead">
<div class="container">
<span class="masthead-logo"><span class="mega-octicon
octicon-mark-github"></span>GitHub readme preview</span>
</div>
</header>
<div class="container">
<div id="readme" class="markdown-body">
<p>Rendering markdown, please wait...</p>
</div>
<footer class="footer">Rendering by
GitHub,
styling by Primer.</footer>
</div>
</body>
</html>
Developer notes
Typically, I wrap my code in an IIFE, but in this case, I didn't see the need, and thought I'd keep it concise
I haven't bothered supporting backlevel IE
For conciseness, I have omitted the error handling code (do you believe me?!)
I'd welcome JavaScript programming tips
Ideas
I'm considering creating a GitHub repository for this HTML file, and putting the file in the gh-pages branch, so that GitHub serves it as a "normal" web page. I'd tweak the file to accept a complete URL - of the README (or any other Markdown file) - as the query string. I'm curious to see whether being hosted by GitHub would sidestep the GitHub API request limit, and whether I run afoul of cross-domain issues (using an Ajax request to get the Markdown from a different domain than the domain serving the HTML page).
Original version (deprecated)
I've preserved this record of the original version for curiosity value.
This version had the following issues that are solved in the current version:
It required some related files to be downloaded
It didn't support being dropped into the same directory as the README.md
Its HTML was more brittle; more susceptible to changes in GitHub
The github directory contains the "preview" HTML file and related files:
.../github/
readme-preview.html
github.css
github2.css
octicons.eot
octicons.svg
octicons.woff
I downloaded the CSS and octicons font files from GitHub:
https://assets-cdn.github.com/assets/github- ... .css
https://assets-cdn.github.com/assets/github2- ... .css
https://github.com/static/fonts/octicons/octicons.* (eot, woff, svg)
I renamed the CSS files to omit the long string of hex digits in the original names.
I edited github.css to refer to the local copies of the octicons font files.
I examined the HTML of a GitHub page, and reproduced enough of the HTML structure surrounding the readme content to provide reasonable fidelity; for example, the constrained width.
The GitHub CSS, octicons font, and HTML "container" for the readme content are moving targets: I will need to periodically download new versions.
I toyed with using CSS from various GitHub projects. For example:
<link rel="stylesheet" type="text/css"
href="http://rawgit.com/sindresorhus/github-markdown-css/gh-pages/github-markdown.css">
but eventually decided to use the CSS from GitHub itself.
Source
Here's the HTML file (readme-preview.html):
<!DOCTYPE html>
<!-- Preview a GitHub README.md.
Copy this file to a directory that contains repo directories.
Specify a repo name in the query string. For example:
http://localhost/github/readme-preview.html?myrepo
-->
<html>
<head>
<title>Preview GitHub readme</title>
<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<!-- Downloaded copies of the CSS files served by GitHub.
In github.css, the #font-face for font-family:'octicons'
has been edited to refer to local copies of the font files -->
<link rel="stylesheet" type="text/css" href="github.css"/>
<link rel="stylesheet" type="text/css" href="github2.css"/>
<style>
body {
margin-top: 1em;
}
</style>
<script type="text/javascript">
//<![CDATA[
var HTTP_STATUS_OK = 200;
var URL_API_GITHUB_RENDER_MARKDOWN = "https://api.github.com/markdown/raw";
var README_FILE_NAME = "README.md";
var repo = location.search.substring(1);
// Get Markdown, then render it as HTML
function getThenRenderMarkdown() {
var xhr = new XMLHttpRequest();
xhr.open("GET", repo + "/" + README_FILE_NAME, true);
xhr.responseType = "text";
xhr.onload = function(e) {
if (this.status == HTTP_STATUS_OK) {
// Response text contains Markdown
renderMarkdown(this.responseText);
}
}
xhr.send();
}
// Use the GitHub API to render Markdown as HTML
function renderMarkdown(markdown) {
var xhr = new XMLHttpRequest();
xhr.open("POST", URL_API_GITHUB_RENDER_MARKDOWN, true);
xhr.responseType = "html";
xhr.onload = function(e) {
if (this.status == HTTP_STATUS_OK) {
document.getElementById("readme-content").innerHTML = this.response;
}
}
xhr.send(markdown);
}
window.onload = getThenRenderMarkdown;
//]]>
</script>
</head>
<body>
<!-- The following HTML structure was copied from live GitHub page on 2015-12-01,
except for the "readme-content" id of the article element,
which was coined for this preview page.-->
<div class="main-content" role="main">
<div class="container repo-container new-discussion-timeline experiment-repo-nav">
<div class="repository-content">
<div id="readme" class="boxed-group flush clearfix announce instapaper_body md">
<h3><span class="octicon octicon-book"></span>README.md</h3>
<article class="markdown-body entry-content"
itemprop="mainContentOfPage"
id="readme-content"><p>Rendering markdown...</p></article>
</div>
</div>
</div>
</div>
</body>
</html>
For Visual Studio users (not VS CODE).
Install Markdown Editor extension
This way, when you open a README.md you'll have a live preview on right side.
You may want to take a look at this one:
https://github.com/kristjanjansen/md2html
For Github or Bitbucket theme, could use online editor mattstow, url: http://writeme.mattstow.com
Just searching the web gives many heres one:
https://stackedit.io/
SublimeText 2/3
Install package: Markdown Preview
Options:
Preview in browser.
Export to html.
Copy to clipboard.
Markdown​Preview, the plugin for Sublime Text mentioned in an earlier comment is not compatible with ST2 any more, but only supports Sublime Text 3 (since spring 2018).
What's neat about it: it supports GFM, GitHub Flavored Markdown, which can do a bit more than regular Markdown. This is of relevance if you want to know what your .mds will look like on GH exactly. (Including this bit of info because the OP didn't add the GFM tag themselves, and others looking for a solution might not be aware of it either.)
You can use it with the GitHub API if you are online, though you should get a personal access token for this purpose because API calls without authentication are limited. There's more info on Parsing GFM in the plugin's docs.
I am using markdownlivepreview:
https://markdownlivepreview.com/
It is very easy, simple and fast.
Since 2012 (when this question was created) GitHub itself can:
create and display a preview of a Markdown document in a regular repository (it always did, since Aug. 2011)
or, if you don't want to impact directly your repository, do the same with gist (since Dec. 2020)
Even without committing a gist, you can, since Nov. 2021, preview a Markdown document in a Gist you are editing (but not yet committing)
Once the preview of that gist looks good, you can copy the markdown from said gist to your local README.md, add, commit and push.
If you're using Pycharm (or another Jetbrains IDE like Intellij, RubyMine, PHPStorm, etc), there are multiple free plugins for Markdown support right in your IDE that allow real-time preview while editing. The Markdown Navigator plugin is quite good. If you open an .md file in the IDE, recent versions will offer to install supporting plugins and show you the list.
Use Jupyter Lab.
To install Jupyter Lab, type the following in your environment:
pip install jupyterlab
After installation, browse to the location of your markdown file, right-click the file, select "Open With" then click "Markdown Preview".
For Visual Studio Code, I use
Markdown Preview Enhanced extension.
I know this question is old perhaps someone was googling how to and reached here.
That is how I saw this question anyway.
You can use atom text editor and toggle markdown preview even in github style.
Press
ctrl+shift+m
The window will pop up or use Packages-->Markdown Preview.
Hope this helps someone.
One way is using the Pandoc (very useful).
Copy your Markdown plaint text to clipboard
Run:
xsel -b | pandoc -s -f markdown -t html | xclip -selection clipboard -t text/html | xsel -b
Paste the generated formatted text (for example on an email or LibreOffice).
You said you are using Linux. You'll need to just install pandoc, xsel and xclip packages.
MarkdownViewerPlusPlus
is a "[...]Notepad++ Plugin to view a Markdown file rendered on-the-fly
Features
Dockable panel (toggle) with a rendered HTML of the currently selected file/tab
CommonMark compliant (0.28)
Synchronized scrolling
Custom CSS integration
HTML and PDF Export
Notepad++ Unicode Plugin
[...]"
I have found that markdownlivepreview.com is pretty close to vanilla GitLab markdown.
Other viewers interpreted commands slightly differently than GitLab does.
I just create a "feature" branch and push it to github where I make changes, which become visible exactly how they will look in github.
Then, when I'm satisfied, I rebase back to main or do a pull request to main, whichever process you happen to be using.
You rarely need to test locally when using git, unless your repository is behind a corp firewall, or need to work offline.
In such cases, both Atom and VScode have decent Markdown renderers, not good enough to show how your changes will look on github, but good enough to see if your changes are going in the right direction.
You could use the static site editor: with GitLab 13.0 (May 2020), it comes with a WYSIWYG panel.
WYSIWYG for the Static Site Editor
Markdown is a powerful and efficient syntax for authoring web content, but even seasoned authors of Markdown content can struggle to remember some of the less-frequently used formatting options or write even moderately-complex tables from scratch.
There are some jobs better accomplished with a rich text, “What You See Is What You Get” (WYSIWYG) editor.
GitLab 13.0 brings a WYSIWYG Markdown authoring experience to the Static Site Editor with formatting options for common formatting options like headers, bold, italics, links, lists, blockquotes, and code blocks.
The WYSIWYG editor also removes the onerous task of editing tables in Markdown by letting you visually edit table rows, columns and cells in the same way you would edit a spreadsheet. For those more comfortable writing in raw Markdown, there’s even a tab for switching between WYSIWYG and plain text editing modes.
See documentation and issue.
Again, you would use it only to write your README: once it looks good, you can report it back to your original project.
But the point is: you don't need no more any thrid-party markdown preview plugin.
And with GitLab 14.2 (August 2021)
Preview Markdown live while editing
Markdown is a fast and intuitive syntax for writing rich web content. Until it isn’t.
Luckily, it’s easy to preview the rendered output of Markdown to ensure the accuracy of your markup from the Preview tab.
Unfortunately, the context switch required to move between the raw source code and the preview can be tedious and disruptive to your flow.
Now, in both the Web IDE and single file editor, Markdown files have a new live preview option available. Right-click the editor and select Preview Markdown or use Command/Control + Shift + P to toggle a split-screen live preview of your Markdown content.
The preview refreshes as you type, so you can be confident that your markup is valid and will render as you intended.
See Documentation and Epic.
See GitLab 14.6 (December 2021)
Toggle wiki editors seamlessly
Toggle wiki editors seamlessly
Editing wiki pages with the new rich Markdown editor makes it easier for everyone to contribute regardless of how well they know Markdown syntax.
You may also prefer to write raw Markdown in some situations, but use the WYSIWYG interface for more complex or tedious formatting tasks, like creating tables.
Previous versions of GitLab required you to save changes before switching between the rich Markdown editor and the Markdown source, adding more steps and friction to your edits.
In GitLab 14.6 you can now seamlessly switch between the two editing experiences without committing your changes, choosing the editor that suits your needs at any given moment.
See Documentation and Issue.
See also GitLab 15.6 (November 2022)
Default split view for Markdown preview in the Web Editor
The ability to preview Markdown files side by side while editing was introduced in GitLab 14.2.
With this release, we’ve made the split view the default experience for previewing Markdown in the Web Editor.
In the Preview tab, you can now see a live Markdown preview that updates as you type alongside your content.
This way, you can be confident that your markup is valid and renders as you intended without having to switch between the Write and Preview tabs.
See Documentation and Issue.
You can install chrome extension "Markdown Viewer":
https://chrome.google.com/webstore/detail/markdown-viewer/ckkdlimhmcjmikdlpkmbgfkaikojcbjk?hl=en
For those who wish to develop on their iPads, I like Textastic. You can edit and preview the README.md files without an internet connection, once you have downloaded the document from the cloud.

Problem With HTML5 Application Cache Whitelist - Won't Ignore Items

I'm trying to use HTML5 Application Cache to speed some things up on an iPhone webapp. It works great for storing images, css and JS, but the problem is that it also tries to store the HTML. I haven't been able to get it to ignore the html and stop storing it in the cache. From what I've read, I have to "whitelist" the files and directories that I want to load no matter what. I've tried listing the files I want cached explicitly, and I've tried adding a series of things under the "NETWORK:" heading. I've tried
*
/
/*
http://mysite.com
http://mysite.com/
http://mysite.com/*
None of them seem to work. Is there any way to ignore HTML files by MIME-Type or anything? Any advice would be appreciated.
Ryan
P.S. Of course, my site is not mysite.com..I just used that for simplicity.
I've avoided this problem by NOT referencing a manifest in each page, instead I have the following within each page :
<iframe src="cache.htm"></iframe> - with styles to hide the iframe
inside cache.htm I have :
<!DOCTYPE html>
<html manifest="cache.manifest">
<head>
<meta charset="UTF-8">
<title>Main Cache Resource</title>
</head>
<body></body>
</html>
based on previous tests and discussions with people in the html5 "ecosystem", each html-page that specifies a manifest is automatically cached as well.