/*
* This is simple jEdit beanshell macro to replace all links in current selection to HTML anchors
* (link)
*
* charset: UTF-8
*
* (c) TAAT Digital Technologies 2006
* Tomasz Pęszor
* info at taat dot pl
* http://taat.pl/jedit/
*/
void replace_links(){
if (textArea.getSelectedText()==null) {
mcp=textArea.getCaretPosition();
textArea.selectAll();
sn=true;
}
// add http:// to to only www.
SearchAndReplace.setBeanShellReplace(true);
SearchAndReplace.setRegexp(true);
SearchAndReplace.setIgnoreCase(true);
// add protocols to www.
SearchAndReplace.setSearchString("([^(https?://|ftps?://)])(www\\.)");
SearchAndReplace.setReplaceString("_1+\"http://www.\"");
SearchAndReplace.setIgnoreCase(true);
SearchAndReplace.replace(view);
SearchAndReplace.setSearchString("\\b(www\\.|https?:\\/\\/|ftps?:\\/\\/)([-\\w@:._]+)([-\\w?~=_&%$#*!;\\\'.,:+()\\/]*)\\b");
// anchor content without protocols
// SearchAndReplace.setReplaceString("\"\"+_2+\"\"");
// anchor content with protocols
SearchAndReplace.setReplaceString("\"\"+_1+_2+\"\"");
SearchAndReplace.replace(view);
if (sn==true) {
textArea.selectNone();
len=buffer.getLength();
if (mcp>len) mcp=len;
textArea.setCaretPosition(mcp);
}
}
// main
if(buffer.isReadOnly())
Macros.error(view, "Buffer is read-only.");
else replace_links();
/*
Macro index entry (in DocBook XML)
Anchor_URLs.bsh
This is simple jEdit beanshell macro to replace all links in current selection to HTML anchors
(link)
(c) TAAT Digital Technologies 2006
*/