I need to be able to preserve line breaks in text displayed on a web page when using a highlight+right click context menu function for a chrome extension.
So the text is displayed like this
Some information on one line
Some on the next line
Then some on the last line
When I highlight it and execute my function, it all gets put into the same line like this
Some information on one line Some on the next line Then some on the last line
Is there any way I can preserve the line spaces when processing my highlighted text in javascript?
Here's my code I'm using to grab the highlighted text:
// Set up context menu at install time.
chrome.runtime.onInstalled.addListener(function() {
var context = "selection";
var title = "Get Text";
var id = chrome.contextMenus.create({"title": title, "contexts":[context],
"id": "context" + context});
});
// add click event
chrome.contextMenus.onClicked.addListener(onClickHandler);
// The onClicked callback function.
function onClickHandler(info, tab) {
var message = info.selectionText;
console.log(message);
};