/* * Texy.bsh - a BeanShell macro script for the * jEdit text editor, which converts text (selection[s] or the whole buffer) * in Texy! (http://texy.info) syntax to XHTML. * Version 1.0 * (C) 2007 Jakub Roztocil * @see */ String PHP_BINARY = "php"; String TEXY_SCRIPT = "/home/jakub/bin/texy.php"; String texy2html(String text) { String[] command = new String[] {PHP_BINARY, TEXY_SCRIPT, text}; Process process = Runtime.getRuntime().exec(command); InputStream stdoutStream = process.getInputStream(); BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(stdoutStream)); StringBuffer stdout = new StringBuffer(); String lf = view.getBuffer().getProperty("lineSeparator"); while ((line = stdoutReader.readLine()) != null) { stdout.append(line); stdout.append(lf); } return stdout.toString(); } void transform(int start, int end) { String html = texy2html(buffer.getText(start, end - start)); buffer.remove(start, end - start); buffer.insert(start, html); } int selectionCount = textArea.getSelectionCount(); if (selectionCount > 0) { Selection selection; Selection.Range[] selections = new Selection.Range[selectionCount]; for (int i = selectionCount - 1; i >= 0; i--) { selection = textArea.getSelection(i); transform(selection.start, selection.end); } } else { transform(0, buffer.getLength()); }