22using DescribeParser . Unfold ;
33using System ;
44using System . Collections . Generic ;
5+ using System . Text ;
6+ using System . Text . RegularExpressions ;
57using System . Web ;
8+ using static Org . BouncyCastle . Asn1 . Cmp . Challenge ;
69
710
811namespace DescribeTranspiler . Translators
@@ -12,6 +15,7 @@ namespace DescribeTranspiler.Translators
1215 /// </summary>
1316 public class HtmlBasicTranslator : DescribeUnfoldTranslator
1417 {
18+ public bool IsCensored = false ;
1519 public override bool IsInitialized
1620 {
1721 get ;
@@ -302,25 +306,50 @@ string TranslateProduction(DescribeUnfold u, string id)
302306 }
303307
304308 //replace in template
309+ string ? colval = null ;
305310 if ( u . Decorators . ContainsKey ( id ) )
306311 {
307312 List < DescribeDecorator > decorators = u . Decorators [ id ] ;
308313 foreach ( DescribeDecorator decorator in decorators )
309314 {
310315 if ( decorator . Name == "color" )
311316 {
312- string res = coloredProductionTemplate ! . Replace ( "{TITLE}" , HttpUtility . HtmlEncode ( u . Translations [ id ] ) ) ;
313- res = res . Replace ( "{LINKS}" , linkage ) ;
314- res = res . Replace ( "{COLOR}" , decorator . Value ) ;
315- res = res . Replace ( "{ITEMS}" , items ) ;
316- return res ;
317+ colval = decorator . Value ;
318+ }
319+ else if ( decorator . Name == "sensitive" && IsCensored )
320+ {
321+ string text = u . Translations [ id ] ;
322+ string censored = Regex . Replace ( text , @"\S" , "?" ) ;
323+ u . Translations [ id ] = censored ;
324+ }
325+ else if ( decorator . Name == "secret" && IsCensored )
326+ {
327+ string mask = GenerateRandomDarkSquares ( random . Next ( 10 , 30 ) ) ;
328+ u . Translations [ id ] = mask ;
329+ }
330+ else if ( decorator . Name == "hidden" && IsCensored )
331+ {
332+ string mask = GenerateRandomGreekText ( random . Next ( 40 , 100 ) ) ;
333+ u . Translations [ id ] = mask ;
317334 }
318335 }
319336 }
320- string pt = productionTemplate ! . Replace ( "{TITLE}" , HttpUtility . HtmlEncode ( u . Translations [ id ] ) ) ;
321- pt = pt . Replace ( "{LINKS}" , linkage ) ;
322- pt = pt . Replace ( "{ITEMS}" , items ) ;
323- return pt ;
337+
338+ if ( colval == null )
339+ {
340+ string pt = productionTemplate ! . Replace ( "{TITLE}" , HttpUtility . HtmlEncode ( u . Translations [ id ] ) ) ;
341+ pt = pt . Replace ( "{LINKS}" , linkage ) ;
342+ pt = pt . Replace ( "{ITEMS}" , items ) ;
343+ return pt ;
344+ }
345+ else
346+ {
347+ string res = coloredProductionTemplate ! . Replace ( "{TITLE}" , HttpUtility . HtmlEncode ( u . Translations [ id ] ) ) ;
348+ res = res . Replace ( "{LINKS}" , linkage ) ;
349+ res = res . Replace ( "{COLOR}" , colval ) ;
350+ res = res . Replace ( "{ITEMS}" , items ) ;
351+ return res ;
352+ }
324353 }
325354 string TranslateItem ( DescribeUnfold u , string id )
326355 {
@@ -395,11 +424,87 @@ string TranslateItem(DescribeUnfold u, string id)
395424 {
396425 res = "<span style='text-decoration-line:line-through;'>" + res + "</span>" ;
397426 }
427+ else if ( decorator . Name == "sensitive" && IsCensored )
428+ {
429+ string text = u . Translations [ id ] ;
430+ string censored = Regex . Replace ( text , @"\S" , "?" ) ;
431+
432+ // possible bug here - this is bad way of doing things
433+ // that is hacked into place. Should be refactored
434+ res = res . Replace ( u . Translations [ id ] , censored ) ;
435+ u . Translations [ id ] = censored ;
436+ }
437+ else if ( decorator . Name == "secret" && IsCensored )
438+ {
439+ // possible bug here - this is bad way of doing things
440+ // that is hacked into place. Should be refactored
441+ string mask = GenerateRandomDarkSquares ( random . Next ( 10 , 30 ) ) ;
442+ res = res . Replace ( u . Translations [ id ] , mask ) ;
443+ u . Translations [ id ] = mask ;
444+ }
445+ else if ( decorator . Name == "hidden" && IsCensored )
446+ {
447+ // possible bug here - this is bad way of doing things
448+ // that is hacked into place. Should be refactored
449+ string mask = GenerateRandomGreekText ( random . Next ( 40 , 100 ) ) ;
450+ res = res . Replace ( u . Translations [ id ] , mask ) ;
451+ u . Translations [ id ] = mask ;
452+ }
398453 }
399454 }
400455 return before + res + after ;
401456 }
402457
458+ //more
459+ Random random = new Random ( ) ;
460+ string GenerateRandomGreekText ( int length )
461+ {
462+ // Define a pool of Greek characters and spaces
463+ string pool = "α βγδ εζη θικ λμν ξοπ ρστ υφχ ψω άέή ίόύ ώ " ;
464+
465+ StringBuilder sb = new StringBuilder ( ) ;
466+
467+ // Generate random characters from the pool
468+ for ( int i = 0 ; i < length ; i ++ )
469+ {
470+ char randomChar = pool [ random . Next ( pool . Length ) ] ;
471+ sb . Append ( randomChar ) ;
472+ }
473+
474+ return sb . ToString ( ) ;
475+ }
476+ string GenerateRandomMathText ( int length )
477+ {
478+ // Define a pool of Greek characters and spaces
479+ string pool = "+ - × ÷ = ≠ < > ≤ ≥ ∞ π ∑ ∫ √ ∆ ∇ ∝ ⊕ ⊗ ⊥ ⎰" ;
480+
481+ StringBuilder sb = new StringBuilder ( ) ;
482+
483+ // Generate random characters from the pool
484+ for ( int i = 0 ; i < length ; i ++ )
485+ {
486+ char randomChar = pool [ random . Next ( pool . Length ) ] ;
487+ sb . Append ( randomChar ) ;
488+ }
489+
490+ return sb . ToString ( ) ;
491+ }
492+ string GenerateRandomDarkSquares ( int length )
493+ {
494+ // Define a pool of Greek characters and spaces
495+ string pool = "▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇" ;
496+
497+ StringBuilder sb = new StringBuilder ( ) ;
498+
499+ // Generate random characters from the pool
500+ for ( int i = 0 ; i < length ; i ++ )
501+ {
502+ char randomChar = pool [ random . Next ( pool . Length ) ] ;
503+ sb . Append ( randomChar ) ;
504+ }
505+
506+ return sb . ToString ( ) ;
507+ }
403508
404509
405510 //log
0 commit comments