Skip to content

Commit

Permalink
Add rule for curly quotes to french quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
webaxones committed May 23, 2024
1 parent 822d89f commit 9a44b73
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-components', 'wp-core-data', 'wp-data', 'wp-dom-ready', 'wp-edit-post', 'wp-i18n', 'wp-notices', 'wp-plugins'), 'version' => '408be787993bd68bb94f');
<?php return array('dependencies' => array('react', 'wp-components', 'wp-core-data', 'wp-data', 'wp-dom-ready', 'wp-edit-post', 'wp-i18n', 'wp-notices', 'wp-plugins'), 'version' => 'f64e0d3fe707707318f5');
2 changes: 1 addition & 1 deletion build/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion consistency.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Consistency
* Plugin URI: https://www.webaxones.com
* Description: Fixes typographical consistency
* Version: 1.5.4
* Version: 1.5.5
* Requires at least: 6.1
* Requires PHP: 7.4
* Author: Loïc Antignac
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "consistency",
"version": "1.5.4",
"version": "1.5.5",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Currently, the AutoCorrects offered are as follows:
- **No breaking space after**: Adds a breaking space after a character from this list (, … ) ]) when followed with another character
- **Space before**: Remove any space preceding a character from this list (? ! : ; %)
- **First sentence letter not capitalized**: Capitalize the first letter of a sentence
- etc.

### French language corrections

Expand All @@ -66,6 +67,7 @@ Currently, the AutoCorrects offered are as follows:
- **No breaking space after**: Adds a breaking space after a character from this list (, … ) ]) when followed with another character
- **No non-breaking space after**: Adds a non-breaking space after open french quote having no space after
- **First sentence letter not capitalized**: Capitalize the first letter of a sentence
- etc.

**Ctrl+Z** or **Cmd+Z** right after a correction disables the correction for the next keystroke. It is thus possible to force the non-correction of a character.

Expand Down
7 changes: 6 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: webaxones
Tags: block editor, typography, gutenberg
Requires at least: 6.1
Tested up to: 6.5.2
Stable tag: 1.5.4
Stable tag: 1.5.5
Requires PHP: 7.4
License: GPL-3.0-or-later
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Expand Down Expand Up @@ -31,6 +31,7 @@ For the English language
- "No breaking space after": Adds a breaking space after a character from this list (, … ) ]) when followed with another character
- "Space before": Remove any space preceding a character from this list (? ! : ; %)
- "First sentence letter not capitalized": Capitalize the first letter of a sentence
- etc.

For the French language

Expand All @@ -44,6 +45,7 @@ For the French language
- "No breaking space after": Adds a breaking space after a character from this list (, … ) ]) when followed with another character
- "No non-breaking space after": Adds a non-breaking space after open french quote having no space after
- "First sentence letter not capitalized": Capitalize the first letter of a sentence
- etc.

Ctrl+Z or Cmd+Z right after a correction disables the correction for the next keystroke

Expand All @@ -67,6 +69,9 @@ The locales supported by this plugin are:

== Changelog ==

= 1.5.5 =
* Add rule to replace curly quotes with french quotes for fr_FR & fr_BE because Google Doc transforms double quotes into curved quotes, but does not offer French quotes

= 1.5.4 =
* Sort settings by categories in sidebar
* Add some rules for symbols
Expand Down
3 changes: 0 additions & 3 deletions src/app/fixes.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,12 @@ export const fixIt = props => {

// If the rule depends on previous characters, we need to separate the string taking those characters into account
const captureGroups = textContent.match( reg.mask )
console.log('captureGroups', captureGroups);

if( null === captureGroups || 0 === captureGroups.length ) return
const lengthToGoBack = captureGroups[0].length || 1
// Split the string to process only the part from the cursor position to the end
firstPart = blockContent.substring( 0, cursorPositionInsideHTML - lengthToGoBack )
lastPart = blockContent.substring( cursorPositionInsideHTML - lengthToGoBack, blockContent.length )
console.log('firstPart', firstPart);
console.log('lastPart', lastPart);
// If first part of the string matches but not the lastPart, it means that a character has been typed uncorrected voluntarily before, so it should not be taken into account
isConcerned = reg.mask.test( textContent ) && reg.mask.test( lastPart )

Expand Down
12 changes: 12 additions & 0 deletions src/config/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ export const rules = [
locales: [ 'de_CH' ],
category: 'punctuation'
},
{
// Replaces curly quotes with french quotes
slug: 'curlyToFrenchQuotes',
name: __( 'Curly quotes to french quotes', 'consistency' ),
description: __( 'Replaces curly quotes with french quotes:', 'consistency' )
+ `<span aria-hidden='true' style='display:block;'><code>“ ”</code> <span style='font-size:20px'>→</span> <code>« »</code></span>`,
mask: /“.*?”/, // specific mask with specific process
replace: matched => { return `« ${matched.substring( 1, matched.length - 1 )} »` },
nbMoved: 0,
locales: [ 'fr_FR', 'fr_BE' ],
category: 'punctuation'
},
{
// Replaces a breaking space followed by a character from this list [? ! : ; » € $ £ ¥ ₽ 元 %] with a non-breaking space
slug: 'breakingSpace',
Expand Down

0 comments on commit 9a44b73

Please sign in to comment.