Text Factory Equivalent for BBEdit: Text: Remove Line Breaks?

73 views
Skip to first unread message

Mark Mayberry

unread,
May 24, 2023, 8:16:29 AM5/24/23
to BBEdit Talk
in my work as an editor, I regularly receive manuscripts in *.docx, *.wpd, *.pages, *.rtf, *.pdf formats.  I use Pandoc to convert these files to markdown, and then perform my editing in BBEdit.  When finished I output the edited files to InDesign *.icml files and HTML.

After Pandoc converts these files into markdown, the first step I take in BBEdit is perform a Text (Menu) >> Remove Line Breaks, along with a number of other conversions.  Based upon the helpful advice I received yesterday on this forum, I was able to create a Text Factory performs most of these steps.

However, I cannot figure out which Text Factory command is the equivalent of simply pressing  BBEdit Text (Menu) >> Remove Line Breaks.

Pandoc creates files with a line break at the end of each line of text, and double line breaks at the end of each paragraph.

BBEdit Text (Menu) >> Remove Line Breaks strips away the line breaks from within the paragraphs and leaves double line breaks at the end of each paragraph.  

How can I reproduce this specific action using Text Factory?

Thanks for your assistance!

Yours,

Mark

## Screen Shot #1 Showing MD Text with Line Breaks (as generated by Pandoc conversion):

Screenshot_2023-05-24 07.07.00_WDdzNA.png
## Screen Shot #2 Showing MD Text After Running Text: Remove Line Breaks.  How can I do this automatically using Text Factory?

Screenshot_2023-05-24 07.12.11_uH5bSa.png


Neil Faiman

unread,
May 24, 2023, 9:41:45 AM5/24/23
to BBEdit Talk Mailing List
On May 24, 2023, at 8:16 AM, Mark Mayberry <markma...@gmail.com> wrote:

BBEdit Text (Menu) >> Remove Line Breaks strips away the line breaks from within the paragraphs and leaves double line breaks at the end of each paragraph.  

How can I reproduce this specific action using Text Factory?

I can’t give you a direct answer, but many of the BBEdit Text menu commands amount to commonly used grep replacements, packaged up in an easier-to-use form, and you can always use a search-and-replace in a Text Factory.

As best I can tell, the following grep replacement will give you the Remove Line Breaks behavior you are looking for.

Find: (?s)(?<!\n)\n(?!\n)
Replace: 
(That is a single space as the Replace value.)

The (?s) tells the search string to match across multiple lines.
The (?<!\n) says to find only matches that are not preceded by a new-line. 
The \n Is what the search actually matches — a new-line.
And the (?!\n) says to only find matches that are not followed by a new-line.

In short, the pattern finds all standalone new-lines (i.e., new-lines that are neither preceded nor followed by another new-line) and replaces them with spaces.

Given this input:

abc
def
ghi

jkl
mno

pqr

stu
v
w
x

It changes it to:

abc def ghi

jkl mno

pqr

stu v w x

Regards,
Neil Faiman


Mark Mayberry

unread,
May 24, 2023, 5:06:39 PM5/24/23
to BBEdit Talk Mailing List

Dear Neil,

Thank you so much. Your suggestion to use GREP Search-and-Replace (SnR) commands worked like a charm. I was able several GREP Search and Replace (SnR) to clean up the manuscripts that I must regularly edit.

I know this is a DUMB question, but how do you get a Text Factory to work ONLY on the file that is currently open and visible in BBEdit? I mistakenly applied the Text Factory to all open files before I realized my mistake. To avoid this problem, I specified that the Text Factory ONLY operate on a single saved file. However, means that I must copy the text to be processed to that particular file, and then run the Text Factory.

Again, I have been using BBEdit for several years (since I shifted from Windows to macOS). I have been using the CANONIZE command to clean up imported manuscripts. However, I would like to easily apply this Text Factory (See Attached Screen Capture) to the BBEdit document that is currently visible (without closing or altering any other open BBEdit documents.

Thanks for any input you might share!

Yours,

Mark

--
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/51E31324-9ED7-4E9D-8D5E-F5361041E0AC%40faiman.org.
Screenshot_2023-05-24 15.55.47_Wk4VY6.png

Rich Siegel

unread,
May 24, 2023, 5:09:47 PM5/24/23
to BBEdit Talk Mailing List
On 24 May 2023, at 17:06, Mark Mayberry wrote:

> I know this is a DUMB question, but how do you get a Text Factory to work ONLY on the file that is currently open and visible in BBEdit?

Place it in BBEdit's "Text Filters" folder, which you can get to by choosing "Text Filters" from the Folder submenu on the BBEdit application menu.

More on this in the user manual, but to summarize: filters run on the selection of the active text document, or on the entire document if there is no selection.

Enjoy,

R.

Mark Mayberry

unread,
May 24, 2023, 6:12:52 PM5/24/23
to BBEdit Talk Mailing List
Dear Rich,

Thank you so much for the assistance. With some trial and error, I was able to implement your advice, and now the Text Factory (which performs hundreds of changes via the GREP commands and the CANONIZE command) can be applied to any open document window by pressing the assigned shortcut (CTRL-V).

I love BBEdit. Around 1980, I started using computers (Kaypro (CP/M) > Vic-20 & Commodore 64 > followed by a succession of homebuilt and purchased Windows computers).

With the arrival of Apple Silicon, I jumped ship from Windows to macOS, and have rediscovered the joy of computing—after wandering in the Windows wilderness for forty years.

Working with BBEdit is a huge part of the delight! I started with WordStar and other CMP based word-processing programs, but then came Microsoft Word. . . SIGH. Now, with BBEdit, markdown, and Pandoc, the process of working with text is a pleasant experience once again.

Thanks for a great product. I’m sorry it took me so long to discover BBEdit. Happy 30th anniversary!

Yours,

Mark
> --
> This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
> ---
> You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/592A84AE-D752-4FC0-B0B9-62E9963B89A9%40barebones.com.

Christopher Stone

unread,
May 24, 2023, 7:42:32 PM5/24/23
to BBEdit-Talk
On May 24, 2023, at 07:16, Mark Mayberry <markma...@gmail.com> wrote:

However, I cannot figure out which Text Factory command is the equivalent of simply pressing  BBEdit Text (Menu) >> Remove Line Breaks.


Hey Mark,

Surprisingly there isn't one...

You have to roll-your-own via a RegEx, AppleScript-filter, or text-filter.

I tend to turn to AppleScript for this sort of thing.

Note how you can mix and match AppleScript and Text Factories. In this instance it's easy enough to employ BBEdit's own 'remove line breaks' command.

Glad you're enjoying the Mac and BBEdit ( and Keyboard Maestro :).

-Chris



--------------------------------------------------------
# Auth: Christopher Stone <script...@thestoneforge.com>
# dCre: 2023/05/24 18:30
# dMod: 2023/05/24 18:30 
# Appl: BBEdit, System Events
# Task: Run a Specific Text Factory and ‘remove line breaks’ on the Front Document.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @System_Events, @Text-Factory, @Remove_Line_Breaks
--------------------------------------------------------

set textFactoryFile to "~/Library/Application Support/BBEdit/Text Filters/Text Factories/TEST.textfactory"
tell application "System Events" to set textFactoryFile to (POSIX path of disk item textFactoryFile)

tell application "BBEdit"
    set frontDoc to front text document
    apply text factory textFactoryFile to frontDoc
    tell frontDoc's text
        remove line breaks
    end tell
end tell

--------------------------------------------------------

Kaveh Bazargan

unread,
May 25, 2023, 4:02:34 AM5/25/23
to bbe...@googlegroups.com
Well done Mark for persevering. Word was indeed a step backwards and it continues to impede progress of mankind. Did you ever use Qued/M from Nisus? it was a great product with a built in programming language too. And Nisus was wonderful as you could do complex searches and with styles as part of searches...



--
Kaveh Bazargan PhD
Director
Accelerating the Communication of Research
  https://rivervalley.io/gigabyte-wins-the-alpsp-scholarly-publishing-innovation-award-using-river-valleys-publishing-technology/

Mark Mayberry

unread,
May 25, 2023, 6:29:52 AM5/25/23
to BBEdit-Talk

Dear Chris,

Thanks for the sample AppleScript. I have Sal Soghoian’s AppleScript 1-2-3 book as a reference, but it’s a little hard for me to wrap my head around this “human language” approach. However, I have implemented several short AppleScripts that I use with BetterTouchTool and my Stream Deck. In the mean time, I added the GREP command that Neil suggested, and “Boom!” IT WORKED!

At this point, I have a growing Text Factory that performs a variety of edits on manuscripts that I must edit.

Previously, I had been saving the GREP commands and using them in the Find and Replace window of BBEdit. However, it is much quicker to string them together in one Text Factory.

I appreciate the help!

Yours,

Mark

--
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages