<commit_before>require 'nokogiri'
require 'text/hyphen'
      
module Jekyll
  module HyphenateFilter
        
    def hyphenate(content)
      # Initialize Hyphen 
      # (you can change the language as you wish, we're from Finland ;)
      hh = Text::Hyphen.new(:language => 'fi', :left => 2, :right => 2)
      
      # Parse html with Nokogiri
      fragment = Nokogiri::HTML::DocumentFragment.parse(content)     
      
      # Grab the html as it is
      html = fragment.inner_html
      
      # Loop through every paragraph
      fragment.css('p').each do |p|
        h = p.content
        
        # Loop through every word
        p.content.split.each do |w|
          # Replace original word with a hyphenated one
          h = h.gsub(w, hh.visualize(w, '&shy;'))
        end
        
        # Replace original paragraph with a hyphenated one
        html = html.gsub(p, h)
      end
      
      # Return hyphenated html
      html
      
    end
    
  end
end

Liquid::Template.register_filter(Jekyll::HyphenateFilter)<commit_msg>Preventing the last word in a paragraph from being hyphenated.<commit_after>require 'nokogiri'
require 'text/hyphen'
      
module Jekyll
  module HyphenateFilter
        
    def hyphenate(content)
      # Initialize Hyphen 
      # (you can change the language as you wish, we're from Finland ;)
      # note: english is en_us or en_uk not just en
      hh = Text::Hyphen.new(:language => 'fi', :left => 2, :right => 2)
      
      # Parse html with Nokogiri
      fragment = Nokogiri::HTML::DocumentFragment.parse(content)     
      
      # Grab the html as it is
      html = fragment.inner_html
      
      # Loop through every paragraph
      fragment.css('p').each do |p|
        h = p.content
        
        # Loop through every word
        p.content.split.each do |w|
          # Replace original word with a hyphenated one
          # unless it is the last word in a paragraph
          if w != p.content.split.last
            h = h.gsub(w, hh.visualize(w, '&shy;'))
          end
        end
        
        # Replace original paragraph with a hyphenated one
        html = html.gsub(p, h)
      end
      
      # Return hyphenated html
      html
      
    end
    
  end
end

Liquid::Template.register_filter(Jekyll::HyphenateFilter)
{'fraction_non_alphanumeric': 0.08463541666666667, 'fraction_numerical': 0.001736111111111111, 'mean_word_length': 1.9214195183776932, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2426568', 'n_tokens_mistral': 723, 'n_tokens_neox': 688, 'n_words': 212}