Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor odie2

    (@odie2)

    Hi,

    I think you can do it with overwriting onbeforehyphenationhandler.

    As I still didn’t provided option to type own options in textarea, you have to modify code files (which will be overwritten with plugin update).

    1. Open /wp-content/plugins/hyphenator/plugin.php.
    2. Go to lines 134-143.
    3. Replace

    if ( ! empty( $hyphenator_defaultlanguage ) )
    				$hyphenatorConfig['defaultlanguage'] = $hyphenator_defaultlanguage;
    
    			$hyphenatorExceptions = ( ! empty( $hyphenator_addexceptions ) ? "Hyphenator.addExceptions( '', '{$hyphenator_addexceptions}' );\n\t" : '' )
    		?>
    <script type="text/javascript">
    	Hyphenator.config( <?php echo json_encode( $hyphenatorConfig ); ?> );
    	<?php echo $hyphenatorExceptions; ?>
    Hyphenator.run();
    </script>

    with

    if ( ! empty( $hyphenator_defaultlanguage ) )
    				$hyphenatorConfig['defaultlanguage'] = $hyphenator_defaultlanguage;
    
    			$hyphenatorConfig['onafterwordhyphenation'] = "function ( word ) {
    	if ( word.length > 0 && typeof word == 'string' )	 {
    		var first_letter = word.substr( 0, 1 );
    		if ( ! isNaN( first_letter ) ) return word;
    
    		if ( first_letter == first_letter.toUpperCase() ) {
    			console.debug(word + ' : ' + first_letter + ' / ' + first_letter.toUpperCase());
    			word = word.replace( new RegExp( String.fromCharCode( 173 ), 'g' ), '' );
    		}
    	}
    
    	return word;
    }";
    
    			$value_arr = array();
    			$replace_keys = array();
    			foreach ( $hyphenatorConfig as $key => &$value ) {
    				if ( strpos( $value, 'function (' ) === 0 || strpos( $value, 'function(' ) === 0 ) {
    					$value_arr[] = $value;
    					$value = '%' . $key . '%';
    					$replace_keys[] = '"' . $value . '"';
    				}
    			}
    
    			$json = json_encode( $hyphenatorConfig );
    			$json = str_replace( $replace_keys, $value_arr, $json );
    
    			$hyphenatorExceptions = ( ! empty( $hyphenator_addexceptions ) ? "Hyphenator.addExceptions( '', '{$hyphenator_addexceptions}' );\n\t" : '' )
    		?>
    <script type="text/javascript">
    	Hyphenator.config( <?php echo $json; ?> );
    	<?php echo $hyphenatorExceptions; ?>
    Hyphenator.run();
    </script>

    Greetings

    Thread Starter Sam Lowry

    (@sam-lowry)

    Thank you. I’ll give it a try. If you can incorporate this as an option within the plugin, I’m sure I’m not the only one who’d like this feature.

    Plugin Contributor odie2

    (@odie2)

    Perhaps when I finally add textarea for every possible option provided by Hyphenator.js, I will also add some presets like this.

    Let me know if it works for you, as for me.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Possible to prevent all Capitalized words from hyphenation?’ is closed to new replies.