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

Comments

Projects
None yet
1 participant
@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 from When printing, code is display as <ul> instead of <code> to When printing, code is displayed as <ul> instead of <code> Oct 19, 2015

@ryanpcmcquen ryanpcmcquen changed the title from When printing, code is displayed as <ul> instead of <code> to When printing, code is displayed as `<ul>` instead of `<code>` Oct 19, 2015

@ryanpcmcquen ryanpcmcquen changed the title from When printing, code is displayed as `<ul>` instead of `<code>` to When printing, code is displayed as <ul> instead of <code> Oct 19, 2015

@ryanpcmcquen

This comment has been minimized.

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