Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When printing, code is displayed as <ul> instead of <code> #33

Open
ryanpcmcquen opened this issue Oct 19, 2015 · 1 comment
Open

When printing, code is displayed as <ul> instead of <code> #33

ryanpcmcquen opened this issue Oct 19, 2015 · 1 comment

Comments

@ryanpcmcquen
Copy link

@ryanpcmcquen ryanpcmcquen commented Oct 19, 2015

Take this example:

https://hackpad.com/ep/pad/static/nOUvKlt6cXY

I can process the HTML using the following JavaScript, and it now displays as code, instead of an HTML list:

[].slice.call(document.querySelectorAll('ul.code li')).forEach(function (oldMarkup) {
    var newMarkup = document.createElement('div');
    newMarkup.innerHTML = oldMarkup.innerHTML;
    oldMarkup.parentNode.insertBefore(newMarkup, oldMarkup);
    oldMarkup.parentNode.removeChild(oldMarkup);
});

[].slice.call(document.querySelectorAll('ul.code')).forEach(function (oldMarkup) {
    var newMarkup = document.createElement('code');
    newMarkup.innerHTML = oldMarkup.innerHTML;
    oldMarkup.parentNode.insertBefore(newMarkup, oldMarkup);
    oldMarkup.parentNode.removeChild(oldMarkup);
});

Here is an example of it in action:
https://jsfiddle.net/ryanpcmcquen/fgyg6v7u/

@ryanpcmcquen ryanpcmcquen changed the title When printing, code is display as <ul> instead of <code> When printing, code is displayed as <ul> instead of <code> Oct 19, 2015
@ryanpcmcquen ryanpcmcquen changed the title When printing, code is displayed as <ul> instead of <code> When printing, code is displayed as `<ul>` instead of `<code>` Oct 19, 2015
@ryanpcmcquen ryanpcmcquen changed the title When printing, code is displayed as `<ul>` instead of `<code>` When printing, code is displayed as <ul> instead of <code> Oct 19, 2015
@ryanpcmcquen
Copy link
Author

@ryanpcmcquen ryanpcmcquen commented Oct 22, 2015

Here is a much more efficient way to write it:

function cleanUpHackpadMarkup(selector, elementType) {
  [].slice.call(document.querySelectorAll(selector)).forEach(function(oldMarkup) {
    var newMarkup = document.createElement(elementType);
    newMarkup.innerHTML = oldMarkup.innerHTML;
    oldMarkup.parentNode.insertBefore(newMarkup, oldMarkup);
    oldMarkup.parentNode.removeChild(oldMarkup);
  });
}
cleanUpHackpadMarkup('ul.code li', 'div');
cleanUpHackpadMarkup('ul.code', 'code');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant