Here are a couple methods:
Add the attribute while the author is in edit mode. Implement your own Text component and configure your dialog to use an event listener that adds the attribute to each paragraph tag in your component. You could listen to the "valid" event that fires when the author clicks the OK button in the widget. With this method the added attribute would get stored in the JCR. See documentation: http://dev.day.com/docs/en/cq/current/developing/widgets.html
Thank you for your help.
Method 1: I don't have much experience with changing the widgets and adding a listener. Is there a sample code that you can point me to please?
Method 2: Might not work because I only want to set the custom attribute on selected text components.
Adobe has a good tutorial on event listeners in widgets. It is available as a package named "Using ExtJS Widgets" found in Package Share. Login to Package Share on your local CQ instance and download this package. The package installs to /apps/extjstraining. The Dynamic Dialogs chapter has several examples of listeners. The tutorial is explained at http://dev.day.com/docs/en/cq/current/developing/widgets.html .