Sunday, September 27, 2015

Maintaining syntax coloring when pasting code on blogger

Problem:
What code looks like when it doesn't maintain syntax coloring on blogger:
    private static void removeChildrenOfEmptyParents() {
        for (String parent : reverseIndex.keySet()) {
            if (map.containsKey((parent))) {
                for (String child : reverseIndex.get(parent)) {
                    map.remove(child);
                }
            }
        }
    }

When it looks like with syntax coloring:
private static void removeChildrenOfEmptyParents() { for (String parent : reverseIndex.keySet()) { if (map.containsKey((parent))) { for (String child : reverseIndex.get(parent)) { map.remove(child); } } } }

Solution:
1. Get Notepad++ (NPP): https://notepad-plus-plus.org/download/v6.8.3.html
2. Paste code into NPP, or open the source file
3. Set the appropriate language in the Language menu
4. Plugins > NppExport > Export to HTML
5. Open the HTML file in a browser
6. Copy and paste into blogger

Reference: http://superuser.com/a/578059 

No comments:

Post a Comment

There was an error in this gadget