Link Search Menu Expand Document

Shuffling text items

Table of contents

  1. Inline Shuffling
  2. Shuffling non-contiguous areas
  3. Nested shuffling
    1. Resolution of nested tags
    2. Deadlocks
  4. Advanced

Inline Shuffling

Items can easily be shuffled using the mix tag. Items to be shuffled must be separated by ||.

/** Default Shuffle */
filterManager.install(closet.recipes.shuffle({ tagname: 'mix' }))
Capitals of Europe: [[mix::Paris||Rome||Berlin||London]]
Capitals of Asia: [[mix::New Delhi||Beijing||Seoul]]

Shuffling non-contiguous areas

If you want to shuffle non-contiguous areas, you need to use numbered tags. Instead of using mix, you should use mix1, mix2, etc.

/** Default Shuffle */
filterManager.install(closet.recipes.shuffle({ tagname: 'mix' }))
[[mix1::A soldier’s a man]]
[[mix1::A life’s but a span]]
[[mix1::Why then let a soldier drink.]]

When using numbered mix tags, they will preserve their original amount of items.

/** Default Shuffle */
filterManager.install(closet.recipes.shuffle({ tagname: 'mix' }))
Reddish colors: [[mix1::magenta||pink]]
Blueish colors: [[mix1::indigo||cyan||teal]]
Greenish colors: [[mix1::lime]]

Nested shuffling

You can also shuffle in a nested style. This is useful if you have multiple levels of logical units, that you want to shuffle around. Think of shuffling paragraphs, and the sentences within; or sentences, and the words within.

/** Default Shuffle */
filterManager.install(closet.recipes.shuffle({ tagname: 'mix' }))
[[mix1::The continent of Asia has the following countries: [[mix::Singapore||China||Kazakhstan||Pakistan||India]]]]
[[mix1::The continent of Africa has the following countries: [[mix::Ghana||Senegal||Ethiopia||Egypt]]]]

Resolution of nested tags

You can shuffle as one-sided as you want to. Closet will try to resolve the shuffling in the most logical way possible. Take a look at the following example:

/** Default Shuffle */
filterManager.install(closet.recipes.shuffle({ tagname: 'mix' }))
[[mix1::[[mix2::[[mix3::I am nested very deeply]]]]]]
[[mix1::I am nested with only one level]]

Closet will start with mix3 and work its way outside, until it will finally shuffle the mix1 tags. If there is no logical way to shuffle the elements, it will cause something called a deadlock.

Deadlocks

/** Default Shuffle */
filterManager.install(closet.recipes.shuffle({ tagname: 'mix' }))
[[mix2::I [[mix3::will [[mix1::a||b||c]]]]]]]]
[[mix3::never [[mix2::resolve [[mix1::x||y||z]]]]]]

In the example above, initially mix1 will be shuffled. However after that, mix2 in the first row will wait for mix3 to finish; and mix3 in the second row will wait for mix2 to finish. After a few rounds, this operation will time out, and the remaining tags will stay unresolved.


Advanced

You can stylize the appearance of shuffled items however you like.

/** Fancy shuffle */
const colorWheel = function*() {
  while (true) {
    yield 'pink'
    yield 'lime'
    yield 'yellow'
  }
}

const cw = colorWheel()
cw.next()

const colorfulWithMiddleDot = closet.Stylizer.make({
  separator: '・',
  mapper: v => (
    `<span style="color: ${cw.next().value};">${v}</span>`
  ),
  processor: v => `〈${v}〉`,
})

const withMiddleDot = closet.Stylizer.make({
  separator: '・',
})

const withSlash = closet.Stylizer.make({
  separator: ' / ',
})

const withVs = closet.Stylizer.make({
  separator: ' vs ',
  mapper: (v, i) => `${i}: ${v}`
})

filterManager.install(
  closet.recipes.shuffle({
    tagname: 'cmix',
    stylizer: colorfulWithMiddleDot,
  }),

  closet.recipes.shuffle({
    tagname: 'amix',
    stylizer: withMiddleDot,
  }),

  closet.recipes.shuffle({
    tagname: 'vmix',
    stylizer: withVs,
  }),

  closet.recipes.shuffle({
    tagname: 'mix',
    stylizer: withSlash
  }),
)
すべての僕の[[cmix::想い||心||悲しみ||幸せ]]は…

In the case that you want multiple shuffling styles at the same time, you can put each filter on different keywords.

/** Fancy shuffle */
const colorWheel = function*() {
  while (true) {
    yield 'pink'
    yield 'lime'
    yield 'yellow'
  }
}

const cw = colorWheel()
cw.next()

const colorfulWithMiddleDot = closet.Stylizer.make({
  separator: '・',
  mapper: v => (
    `<span style="color: ${cw.next().value};">${v}</span>`
  ),
  processor: v => `〈${v}〉`,
})

const withMiddleDot = closet.Stylizer.make({
  separator: '・',
})

const withSlash = closet.Stylizer.make({
  separator: ' / ',
})

const withVs = closet.Stylizer.make({
  separator: ' vs ',
  mapper: (v, i) => `${i}: ${v}`
})

filterManager.install(
  closet.recipes.shuffle({
    tagname: 'cmix',
    stylizer: colorfulWithMiddleDot,
  }),

  closet.recipes.shuffle({
    tagname: 'amix',
    stylizer: withMiddleDot,
  }),

  closet.recipes.shuffle({
    tagname: 'vmix',
    stylizer: withVs,
  }),

  closet.recipes.shuffle({
    tagname: 'mix',
    stylizer: withSlash
  }),
)
Shuffling with centered dot: [[amix1::Susan||Joanne||Lisa]]
Shuffling with slashes: [[mix1::Peter||John||Mark]]
Shuffling with centered dot again: [[amix1::Robin||Paula]]

Note how they items from tags with different keywords don’t mix.

For more on setting options, see here