Sentence Spacing

Sentence Spacing

Wrap each sentence in a span, and style the span perhaps. (Not a great solution).

Is there a way to reduce the sentence spacing?

This is happening because you have given more line-height to <p> tag. Keep the line-height: 1.5 of <p> tage which is by default given by Materialize CSS.

How to add spacing before first line of paragraph in VBA?

Swapped two lines of code

.TypeText VBA.vbNewLine

and

.ParagraphFormat.SpaceBefore = 0

Seems that it is important to place .ParagraphFormat after .TypeParagraph or VBA.vbNewLine then it started to work as I wanted.

With Wapp
With .Selection
.TypeParagraph
'Add line spacing
.ParagraphFormat.SpaceBefore = 0
.ParagraphFormat.SpaceAfter = 0
.TypeText St1
.TypeParagraph
'Starts spacing
.ParagraphFormat.SpaceBefore = 6
.BoldRun
'Centers text
.ParagraphFormat.Alignment = 1
.TypeText St2
.BoldRun
.TypeText VBA.vbNewLine
'Ends spacing
.ParagraphFormat.SpaceBefore = 0
.TypeText St3
.TypeText VBA.vbNewLine
.ParagraphFormat.Alignment = 1
End With
End With

Fixing sentences: add space after punctuation but not after decimal points or abbreviations

I understand you want to ignore the periods inside numbers and period-separated single-letter chunks with an optional period right after.

Here is a code snippet that implements the logic I described above:

import re

mystring = 'this is my first sentence with (brackets)in it. this is the second?What about this sentence with D.D.T. in it?or this with 4.5?'

def fix_punctuation(text):
def sentence_case(text):
# Split into sentences. Therefore, find all text that ends
# with punctuation followed by white space or end of string.
sentences = re.findall(r'(?:\d+\.\d+|\b[A-Z](?:\.[A-Z])*\b\.?|[^.!?])+[.!?](?:\s|\Z)', text)

# Capitalize the first letter of each sentence
sentences = [x[0].upper() + x[1:] for x in sentences]

# Combine sentences
return ''.join(sentences)

#add space after punctuation
text = re.sub(r'(\d+\.\d+|\b[A-Z](?:\.[A-Z])*\b\.?)|([.,;:!?)])\s*', lambda x: x.group(1) or f'{x.group(2)} ', text)
#capitalize sentences
return sentence_case(text)

print(fix_punctuation(mystring))
# => This is my first sentence with (brackets) in it. This is the second?
# What about this sentence with D.D.T. in it? Or this with 4.5?

See the Python demo.

The re.findall pattern, (?:\d+\.\d+|\b[A-Z](?:\.[A-Z])*\b\.?|[^.!?])+[.!?](?:\s|\Z), matches

  • (?:\d+\.\d+|\b[A-Z](?:\.[A-Z])*\b\.?|[^.!?])+ - one or more occurrences of
    • \d+\.\d+ - one or more digits, ., one or more digits
    • | - or
    • \b[A-Z](?:\.[A-Z])*\b\.? - a word boundary, an uppercase letter, zero or more repetitions of a period and an uppercase letter, a word boundary and an optional .
    • | - or
    • [^.!?] - a char other than ., ! and ?
  • [.!?] - ., ! or ?
  • (?:\s|\Z) - a whitespace or end of string.

The re.sub pattern, (\d+\.\d+|\b[A-Z](?:\.[A-Z])*\b\.?)|([.,;:!?)])\s*, matches and captures into Group 1 those patterns that we want to skip, and then matches and captures into Group 2 some punctuation chars and then matches any zero or more whitespace chars (to make sure we only have a single space after them), and a custom logic is used in the replacement argument, in the lambda expression.



Related Topics



Leave a reply



Submit